[mod_python] interoperability with cgi module

Chris Foote chris at zeus.foote.com.au
Wed Aug 23 14:12:05 EST 2000


Is there any way of getting the CGI environment from mod_python
(i.e. via req.add_common_vars()) usable by the Python libraries
standard cgi module ?

e.g. something like the following (html form POST's to this script):

import os
import cgi
from mod_python import apache

def handler(req):
	req.content_type  = "text/plain"
	req.send_http_header()
	
	req.add_common_vars()
	
	# add req's CGI vars into the environment
	for k in req.subprocess_env.keys():
		os.environ[k] = req.subprocess_env[k]

	form = cgi.FieldStorage()
	cgi.parse_header(str(req.headers_in))

	len = int(req.headers_in["content-length"])
	form_data = req.read(len)
	cgi.parse_qs(form_data)

	cgi.test()
	if form.has_key("field"):
		req.write('field = ' + form["field"].value + '\n')

	return apache.OK

however, the cgi module doesn't display anything for cgi.test()
and form['field'] doesn't exist.

I'm new to Python, and especially mod_pythod - am I going about
this in the wrong way ?  i.e. should I be bothering with the cgi
module at all ?



Cheers,

Chris Foote                        chris at zeus.foote.com.au




More information about the Mod_python mailing list