[mod_python] How do I serve up .html files?

john spurling synec at viscous.org
Mon Aug 25 14:36:41 EST 2003


On Mon, Aug 25, 2003 at 04:54:28PM -0400, Russell Nelson wrote:
> Maybe this is really an Apache question, but it seems to me like it
> ought to come up in a mod_python context as well.  Can't find it in
> the documentation, the FAQ, or the mailing list archives
> (Aug/Jul/Jun).
> 
> How do I cause my python script to be run when a .html file is accessed?
>     http://angry-economics.russnelson.com/index.html
> 
> How do I cause my python script to be run when any old file is accessed?
>     http://angry-economics.russnelson.com/
> 
> In other words, I want a handler which gets run no matter what the
> rest of the URL is.  You'd think this would be in the documentation,
> enabling people to make fully scripted sites, but it seems not to be.
> 
> I can't insert a /foo.py/ in there because I have to preserve all the
> old URLs.

i think you can do it using the "SetHandler" directive in httpd.conf,
like this:

<Directory "/path/to/document/root">
SetHandler python-program
PythonHandler mymodule
</Directory>

from there, mymodule.py (located in the document root) will handle all
requests. here's a sample to put in mymodule.py:

from mod_python import apache
def handler(req):
    req.content_type = 'text/plain'
    req.write("uri: %s" % req.uri)
    return apache.OK

voila. that'll print out whatever uri gets typed in.

-john

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mailman.modpython.org/pipermail/mod_python/attachments/20030825/32b77b5c/attachment-0003.bin


More information about the Mod_python mailing list