[mod_python] Getting the script name with publisher

d d at hell.art.pl
Wed Mar 1 16:01:05 EST 2006


On Mar 1, 2006, at 9:19 PM, Bart Whiteley wrote:

> In order to generate hyperlinks, I need a reliable way to determine  
> the
> script name while using the publisher handler.  I hunted around for a
> bit, and only found this from years ago that wasn't answered:
> http://www.modpython.org/pipermail/mod_python/2003-September/ 
> 014133.html
>
> I was doing this for a while:
>   req.uri[:-len(req.path_info)]
>
> This worked until I renamed my script to index.py, then it fell apart.
> So, I guess what I really need is not the script name, but the portion
> of the URI prior to the method name.  In some cases this might be the
> script name (possibly without the '.py').  In the case of index.py, it
> might be the folder containing index.py.
>
> As an example, I've set up a script loosely based on hello.py:
> http://modpython.org/live/current/doc-html/hand-pub-intro.html
>
> I place it in /srv/www/htdocs/mptest/index.py (docroot
> is /srv/www/htdocs).
> When I access it like this: http://www/mptest/say/hello,
> I see the following vars:
> SCRIPT_FILENAME		/srv/www/htdocs/mptest/say
> PATH_INFO		/hello
> SCRIPT_NAME		/mptest/say
>
> In this example, I'd like to isolate "/mptest".
>
> Does anyone have a way to reliable isolate the script name, or the
> folder containing index.py?

You mean `os.path.basename (__file__)` ?

d

PS. Sorry I sent it directly to you the first time ;] I just started  
using this mail client ;]



More information about the Mod_python mailing list