开发者

URLs in mod_python Not Working as Expected

开发者 https://www.devze.com 2023-02-08 14:07 出处:网络
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.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消