Now with publisher handler in Python with 0 comments on Mon Oct 31, 2011 10:34 am
In the previous post I set up a Python cgihandler. This post is about the publisher handler. This time you will need two files again:
The .htaccess has:
And the Python code has:
The decode function parses the form arguments given (if any) and generates the HTML content for the browser. You use this code through URL "http://.../opel/vin/decode". So, it's easy to add more functionality just by adding a function definition into vin.py.
The script vin.py decodes the Opel Vehicle Identification Number. You can try it here: http://www.kta.frihost.org/opel/vin/decode.
I import cgi for cgi.escape.
- opel/.htaccess
opel/vin.py
The .htaccess has:
| Code: |
| AddHandler mod_python .py
PythonHandler mod_python.publisher PythonDebug On Options +MultiViews MultiviewsMatch Handlers |
And the Python code has:
| Code: |
| #!/usr/bin/env python
import re import cgi import cgitb; cgitb.enable() # for troubleshooting ... def decode(req): req.content_type = "text/html" form = req.form ... # Send web page # req.write(content) |
The decode function parses the form arguments given (if any) and generates the HTML content for the browser. You use this code through URL "http://.../opel/vin/decode". So, it's easy to add more functionality just by adding a function definition into vin.py.
The script vin.py decodes the Opel Vehicle Identification Number. You can try it here: http://www.kta.frihost.org/opel/vin/decode.
I import cgi for cgi.escape.