.htaccess with python scripts

n00b question. I have a .htaccess file with the following:

AddHandler python-program .py
PythonHandler index

      

I'm trying to write another program called script2.py, but when I type in fileserver / script2.py, it is redirected to fileserver / index.py. Any way to stop this?

+3


source to share


1 answer


There are various ways to customize mod_python. I think you want python.publisher . The docs show this configuration:

AddHandler python-program .py
PythonHandler mod_python.publisher

      

Then for your example, script2.py would have something like:

def index(req):
    # Your handler here

      

Please note: the documentation says:

This handler allows you to access functions and variables within a module via a URL.



The documentation provides this example (which I modified to use script2.py):

def say(req, what="NOTHING"):
    return "I am saying %s" % what

      

The URL http://www.mysite.com/script2.py/say will return "I say NOTHING". The URL http://www.mysite.com/hello.py/say?what=hello will return "I say hi".

You usually don't want to expose every function and variable.

The traversal will stop and HTTP_NOTFOUND will be returned to the client if:

  • Any of the named objects begins with an underscore ("_"). Use underscores to protect objects that should not be accessible from the Internet.
+3


source







All Articles