[mod_python] how do I eliminate the .py extension in url?

Damjan gdamjan at mail.net.mk
Fri Feb 11 23:18:26 EST 2005


> Put the following in httpd.conf:
> 
> SetHandler mod_python
> PythonHandler module.path.to.handler.file
> 
> Then in the handler file, def a handler that looks for python scripts
> and loads them based on the req.uri. The attached very crufty handler
> might be a good source of amusement.

> def handler(req):
>     # 1. If the file exists & not a directory, serve it.
> 
>     filepath = req.document_root() + req.uri
>     if (os.access(filepath, os.R_OK) 
>     and not os.path.isdir(filepath)) :
>         # req.write("sending file\n")
>         req.sendfile(filepath)
>         return apache.OK

Why don't you return apache.DECLINE, that way even php scripts would
work correctly.

-- 
damjan | дамјан
This is my jabber ID --> damjan at bagra.net.mk <-- not my mail address!!!


More information about the Mod_python mailing list