[mod_python] any way to get the current handler's directory?

Graham Dumpleton grahamd at dscpl.com.au
Sun May 1 01:21:10 EDT 2005


On 01/05/2005, at 1:01 PM, vegetax wrote:

> i need that info to parse the url from a handler.
>
> sys.path[0] works if there is only one "myhandler" per server
>
> Also works this way, but i dont like it:
>
> <Directory "myweb/dir">
>   SetHandler mod_python
>   PythonHandler myhandler
>   PythonOption dirpath "myweb/dir"
> <Directory/>

Depends on which version of mod_python you are using. If you need to be
portable to older versions of mod_python, use:

       if hasattr(req,"hlist"):
         # In mod_python 3.X have the req.hlist member.
         handler_root = req.hlist.directory
       elif hasattr(req,"get_dirs"):
         # In mod_python 2.X have the req.get_dirs() method.
         handler_root = req.get_dirs()["PythonHandler"]

Graham



More information about the Mod_python mailing list