finding domain name

Gabriel Genellina gagsl-py2 at
Wed Sep 24 02:13:27 CEST 2008

En Tue, 23 Sep 2008 09:37:44 -0300, Bobby Roberts <tchendrix at>  

> 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.

That info comes from the "Host" request field, and whether it's available  
or not depends on the web framework in use; for a plain old CGI script, it  
depends on the server configuration. Look at the HTTP_HOST environment  
variable (accessing os.environ, or with the cgi.print_environ() function)

Gabriel Genellina

More information about the Python-list mailing list