Python Apache Handler

S

Scooter

Does anyone have any good examples, or links thereto for using python
as an Apache handler? And I should qualify all of this by saying I'm a
python newbie, and while having experience with Apache, I've never
done anything outside whats "in the box" .

What I'm looking for is how one might use Python not from the CGI/
presentation side but more on the backend...i.e. for each page Apache
serves up examine the request and update some headers, or add a cookie
to the response. Or possibly use Python for writing a custom Apache
logger. I've searched the web but typically end up with pages for
mod_python and writing CGI scripts.

And if you feel this is better posted in an Apache group vs. here, let
me apologize up front.

Thanks
 
G

Gerhard Häring

Scooter said:
Does anyone have any good examples, or links thereto for using python
as an Apache handler? And I should qualify all of this by saying I'm a
python newbie, and while having experience with Apache, I've never
done anything outside whats "in the box" .

What I'm looking for is how one might use Python not from the CGI/
presentation side but more on the backend...i.e. for each page Apache
serves up examine the request and update some headers, or add a cookie
to the response.

I vaguely remembered that mod_python can do such things. Looking again
it seems to be the case:
http://www.modpython.org/live/current/doc-html/pyapi-filter.html
Or possibly use Python for writing a custom Apache
logger. [...]

Maybe http://www.modpython.org/live/current/doc-html/dir-handlers-plh.html
The documentation about this is a joke, though.

Remember that you can write custom Apache loggers quite easily with
"piped logs": http://httpd.apache.org/docs/2.2/logs.html

This looks roughly like this:

CustomLog "|/path/to/my_script.py" common

## begin my_script.py ##
import sys

for line in sys.stdin:
# do stuff
## end ##

-- Gerhard
 
S

Sells, Fred

Mod_python works, but if you are doing anything significant look into
one of the many frameworks like turbogears or django. More structure to
learn but less code when all is said and done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top