Get host name without port in bulb

I just managed to get the host name of my application server in Flask using request.host and request.url_root, but both fields return the host name with its port. I want to use a field / method that returns only the host name without the need to perform a string replacement, if any.

+6
source share
2 answers

There is no Werkzeug (using the WSKI Toolkit Flask tool), which returns only the host name. What you can do is use the urlparse Python module to get the host name from the result Werkzeug gives you:

from urlparse import urlparse o = urlparse("http://127.0.0.1:5000/") print o.hostname # will display '127.0.0.1' 
+5
source

This works for me in a python-flask application.

 from flask import Flask, request print "Base url without port",request.remote_addr print "Base url with port",request.host_url 
0
source

All Articles