[mod_python] writting a handler in python

Graham Dumpleton grahamd at dscpl.com.au
Thu Jun 30 18:21:33 EDT 2005


On 01/07/2005, at 6:10 AM, Alejandro Mery wrote:

>
>> Reading the documentation on the mod_python site would be a good 
>> start.
>>   http://www.modpython.org
>
> i haven't found anything about on python-program on mod_python manual 
> 3.1.3, i guess i should re-reading (on print) carefully but i need to 
> buy ink and paper before.

If you are using mod_python 3.1.X, you can use either "mod_python" or
"python-program" as the first parameter to "AddHandler". If you are
using mod_python 2.7.X, you can only use "python-program". Ie., the
name used changed but old one kept for backward compatibility. As I
didn't know which version of mod_python you were using, I gave the
one which will work in both old and new versions.

>> Having done that, then try and work out what the following does:
>>   # .htaccess file
>>   AddHandler python-program .foo
>>   PythonHandler mod_foo
>>   PythonDebug On
>>   # mod_foo.py file
>>   from mod_python import apache
>>   def handler(req):
>>     req.content_type = "text/plain"
>>     req.send_http_header()
>>     req.write("uri = %s"%req.uri)
>>     return apache.OK
>
> the changes i have tried always end on an error :-\

Are you sure about what version of mod_python you are even using? Are
you perhaps using the wrong documentation for the version you are using?

I would suggest perhaps you follow the examples and suggestions for
problem shooting in:

   http://www.dscpl.com.au/articles/modpython-001.html

Am suggesting this at this point as not clear if you have even got a
simple example going.

It would also help if you are were to post on the list what code you
are using and what errors you are getting. See guidelines at end of
referenced document as to what it is a good idea to supply in the way
of information. Without these details we would just be guessing.

> my last question, how would that be to have mod_foo handling .foo and 
> mod_bar handling .bar

 From memory, in mod_python 3.1.X you can say:

   AddHandler python-program .foo
   PythonHandler mod_foo | .foo

   AddHandler python-program .bar
   PythonHandler mod_bar | .bar

You could then have separate Python code files to handle each extension.




More information about the Mod_python mailing list