[mod_python] Server address

Graham Dumpleton graham.dumpleton at gmail.com
Fri Aug 29 19:47:33 EDT 2008

2008/8/30 Tiago Becker <tiagobecker at gmail.com>:
> Hello guys!
> Im trying to make my own framework for mod python, because none of the
> available suited my needs.
> Im trying to get the server address, without the request object, but i
> couldnt find in the documentation.. is that possible?
> Heres why i need it: i import apache and a configuration file, but that
> config need to know the server address.. as i import the files prior to the
> function that handles the request, i dont have the req object...
> from mod_python import apache
> import sys, os
> #my cfg
> CFG = apache.import_module('cfg/cfg')
> CFG.LOCAL_PATH = os.path.dirname( __file__ )
> ..other imports etc
> def index(req):
>     #this is ther var i would like to get outside the function
>     CFG.URL = 'http://' + req.hostname

Sounds like you are going about it the wrong way. Can you give a
better reason why you need it.

First off, the only server details you can get outside of the context
of a request are those for the main server. If requests are handled
within the context of a VirtualHost then you can't do it. For main
server details do:

  from mod_python import apache
  print apache.main_server.server_hostname

Documentation at:


If you need to construct URLs for use inside of a request, you should use:


Documetation at:



More information about the Mod_python mailing list