[mod_python] interoperability with cgi module

Miguel Marques miguel at yorku.ca
Wed Aug 23 09:35:34 EST 2000


On Wed, 23 Aug 2000 14:12:05 +0930 (CST), Chris Foote <chris at zeus.foote.com.au> wrote:
> 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.
Above try
    form = cgi.parse_qs(form_data)
to get the POST data.  cgi.parse_qs returns a dictionary with the
data.


						Miguel

C. Miguel Marques, York University, Computing & Communications Services
e-mail: miguel at yorku.ca, voice: (416)736-2100x22684, fax: (416)736-5830




More information about the Mod_python mailing list