[mod_python] Getting the script name with publisher

Damjan gdamjan at mail.net.mk
Tue Sep 2 01:15:45 EST 2003

I have this simple script (test.py) that handled by the publisher:

def index(req):
    script_name = req.subprocess_env['SCRIPT_NAME']
    req.content_type = 'text/html'
    buf = "Hello, I'm a script. You can call my other methods:"
    buf = buf + "<br>\n" + req.path_info + "<br>\n"
    buf = buf + '''Go <a href="%s/say">here</a>''' % script_name
    return buf
def say(req, what="NOTHING"):
    return "I am saying %s" % what

Now if this script is called as:
[1]  http://127.1/test.py        -> script_name = /test.py
[2]  http://127.1/test.py/       -> script_name = /test.py/
[3]  http://127.1/test.py/index  -> script_name = /test.py
[4]  http://127.1/test.py/index/ -> script_name = /test.py/index

Now obviosly my implementation of getting the script_name doesn't not 
always get the proper result (the proper result being [1] and [3]). 
What's the proper way to do it?? 
I guess the publisher should know the real script name since it had to
import the file...

Damjan Georgievski
jabberID: damjan at bagra.net.mk

More information about the Mod_python mailing list