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

Graham Dumpleton grahamd at dscpl.com.au
Thu Feb 10 23:37:25 EST 2005


Rob Nichols wrote ..
> On Thu, Feb 10, 2005 at 06:30:32PM -0600, Shawn Harrison wrote:
> > 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.
> 
> Are you using this in a production environment?  If so, can you give a
> rough
> estimate of the cost of "a little python and usually req.sendfile()" compared
> to apache serving up text files?  
> 
> I'm quite new to mod_python, just toying with it for some pet projects.
> It
> seems really cool, but I don't have a feel for the performance yet.  I'll
> do
> some tests "some day" (before I do anything serious), but curious about
> what
> others have found.  

When you use "req.sendfile()", the job of sending back the contents of the
file is carried out by Apache. Thus, it isn't strictly being done by any Python
code.

The alternative to using "req.sendfile()" in this case where the physical
file resides at the same spot as the URL would match to anyway, is to
simply return "apache.DECLINED". By doing this, Apache will continue
to process the request and will serve up the contents of the file as per
normal.

The only real reason to use "req.sendfile()" is where the physical file is
situated in a different location to that where the URL would map to if you
let Apache do its job. For example, if the physical file actually resided
outside of the document tree.

Graham


More information about the Mod_python mailing list