finding domain name

Gerhard Häring gh at ghaering.de
Tue Sep 23 14:49:21 CEST 2008


Bobby Roberts wrote:
> hi group.  I'm new to python and need some help and hope you can
> answer this question.  I have a situation in my code where i need to
> create a file on the server and write to it.  That's not a problem if
> i hard code the path.  However, the domain name needs to be dynamic so
> it is picked up automatically.  The path to our websites is
> 
> home/sites/xxxxx/
> 
> where xxxxx represents the domain name.
> 
> How can I find the domain name of the current url being viewed.

Depends on the technology/web framework. If you use WSGI, you should use 
something like:

host_name = environ.get("HTTP_HOST", None) or environ["SERVER_NAME"]

-- Gerhard




More information about the Python-list mailing list