Gregory Trubetskoy
grisha at modpython.org
Wed Aug 23 09:22:50 EST 2000
Look at how it's done in the cgihandler: http://www.modpython.org/live/mod_python-2.4.1/lib/python/mod_python/cgihandler.py apache.setup_cgi() is what you need. as a shortcut, I think os.env = req.subprocess_env might just do the trick. Grisha -- Gregory (Grisha) Trubetskoy grisha at modpython.org On Wed, 23 Aug 2000, Chris Foote 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. > > 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 > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://www.modpython.org/mailman/listinfo/mod_python >
|