[mod_python] POST variables with SetHandler ?

Jorey Bump list at joreybump.com
Thu Apr 14 10:15:55 EDT 2005


Adrian Immler wrote:

> def function(req):
>   req.content_type = "text/html"
>   fs = FieldStorage(req)
>   for key in fs.keys():
>     req.write( key + ": "+ fs.getfirst(key) + "<br>\n" )

This function is not appropriate for Publisher, which automatically 
handles most of the overhead in your code. Publisher makes form data 
available in the dictionary-like object, req.form:

# foo.py
def showformdata(req):
     formdata = {}
     for key in req.form.keys():
         formdata[key] = req.form[key]
     return formdata

Access the above function like this:

  http://localhost/foo/showformdata?a=123&b=456&b=789

It should return this:

  {'a': '123', 'b': ['456', '789']}

Note that a list will be created if multiple values are returned for the 
same key.


More information about the Mod_python mailing list