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

vegetax vegeta.z at gmail.com
Sun May 1 01:40:30 EDT 2005


Graham Dumpleton wrote:

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


Thanks graham, forgot to mention that i also need the uri part of the
current handler,ie:

<Directory "/var/www/mywebapp/handler_root">
  SetHandler mod_python
  PythonHandler myhandler
  PythonOption dirpath "/mywebapp/handler_root"
<Directory/>

Any way to get this information in one step? without having to   
req.filename[len(req.hlist.directory): ]




More information about the Mod_python mailing list