[mod_python] Server address

Graham Dumpleton graham.dumpleton at gmail.com
Sun Aug 31 02:21:30 EDT 2008


---------- Forwarded message ----------
From: Tiago Becker <tiagobecker at gmail.com>
Date: 2008/8/31
Subject: Re: [mod_python] Server address
To: Graham Dumpleton <graham.dumpleton at gmail.com>


Well, i will probably use more than one .py file... I dont want to
copy all the configuration on each file...
Besides, i work with 5 other developers, each one with their own
virtual server and having to configurate every developer enviroment
seems too much trouble to maintain..

Well, i could import my CFG file inside the function, that would make
the request available (i think :-))... i just wanted to know if there
was any other way to do it.

The fact is that im coming from php where i had a global cfg file for
all the url configurations.. All i want with that is to have a config
file that will get the urls (and others variables) needed so no one
has to worry about that.

Re-reading my post, i saw that i wasnt clear enough :-)
Thanks for you answers and your patience with my 'english' :-)


On Fri, Aug 29, 2008 at 8:47 PM, Graham Dumpleton
<graham.dumpleton at gmail.com> wrote:
>
> 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:
>
>  http://www.modpython.org/live/current/doc-html/pyapi-apmem.html
>  http://www.modpython.org/live/current/doc-html/pyapi-mpserver.html
>  http://www.modpython.org/live/current/doc-html/pyapi-mpsrv-mem.html
>
> If you need to construct URLs for use inside of a request, you should use:
>
>  req.construct_url('/some/path')
>
> Documetation at:
>
>  http://www.modpython.org/live/current/doc-html/pyapi-mprequest-meth.html
>
> Graham


More information about the Mod_python mailing list