URLs in mod_python Not Working as Expected

294 views Asked by At

I'm building a web server with apache and mod_python. I've created index.py as I've seen others do, but unlike others I can't access web pages without adding a .py to the url.

For example, http://127.0.1.1/commentsubmit produces a 404, but http://127.0.1.1/commentsubmit.py brings up the page as expected.

Everything is in my index.py, and http://127.0.1.1/ comes up fine, but nothing else without the .py. My other methods look like this:

def commentsubmit(req):
    rest of method

I'm pretty sure the problem lies in mod_python, but I have no idea what. Is there some sort of configuration setting that might do this? Something other than from mod_python import apache I should be importing?

1

There are 1 answers

0
Gary van der Merwe On BEST ANSWER

Your apache server would have been configured to pass requests to filenames that end in .py to mod_python (if the file exist in the dir.)

There are a number of different solutions to make request to /commentsubmit get passed to your commentsubmit.py handler. The easiest would probably be to to use mod_rewrite. Add this to you .htaacess:

RewriteEngine On
RewriteOptions Inherit
RewriteRule   ^commentsubmit$  commentsubmit.py

This is a dated way to do things. I recommenced that you look at pyramid (or pylons, or django, or one of the million other wsgi frameworks.) You can then have much better control over how to map ulrs to code, using route based url dispatch, or transversal based url dispatch.