[mod_python] Getting the script name with publisher

Graham Dumpleton grahamd at dscpl.com.au
Wed Mar 1 16:48:49 EST 2006

Bart Whiteley wrote ..
> Thanks.  I didn't know about __file__.  I how have this which seems to
> work in all cases: 
> def _baseScript(req):
>     drlen = len(req.subprocess_env['DOCUMENT_ROOT'])
>     if os.path.basename(__file__) == 'index.py':
>         return os.path.dirname(__file__)[drlen:]
>     else:
>         return __file__[drlen:-3]

Will not work when files are in a user account served up by mod_userdir
or where Alias directive is used to map in files outside of the directories
under document root.

Trying to do what you want is actually quite hard and there are a lot of
gotchas. When I get some time I'll try and respond properly.


More information about the Mod_python mailing list