[mod_python] Can't get post vars using Publisher Handler

Robey Holderith robey at flaminglunchbox.net
Fri Oct 15 10:34:46 EDT 2004


Tom wrote:

> Thanks for this tip!
>
> This example should definately be added to the tutorial section of the 
> mod_python-docu, because:
>
> 1. Parsing form-variables is the first thing a newby to mod_python 
> wants to do
>
> 2. No information about req.form() available under:
> http://www.modpython.org/live/current/doc-html/genindex.html
> http://www.modpython.org/live/current/doc-html/pyapi-mprequest-meth.html
> http://www.modpython.org/live/current/doc-html/pyapi-mprequest-mem.html
>
> I spent the last few hours wondering about req.read() (which returned 
> no string, even if req.headers_in["content-length"] showed a length 
> different from zero.
>
>        len = int(req.headers_in["content-length"])
>        req.write("%s" % len);               # printed something about 40
>        req.write("%s" % req.read());  #printed nothing
>
>
>        req.write("%s" % req.form.keys());   # worked fine
>
>
>    pixtur
>    python newby
>
>
>>
>>   <form name="test" action="somefunction" method="POST">
>>     <input type="hidden" name="foo" value="1">
>>     <input type="hidden" name="bar" value="milkyway">
>>     <input type="submit" name="submit" value="Try me!">
>>   </form>
>>
>> the variables will be available in the function like this:
>>
>>   def somefunction(req):
>>       x = req.form['foo']
>>       y = req.form['bar']
>>       result = """<html>
>>   <head>
>>   <title>foobar</title>
>>   </head>
>>   <body>
>>   <p>I would like %s %s. </p>
>>   </body>
>>   </html>
>>       """ % (x, y)
>>       return result
>>
>> Note that the values of multiple form elements of the same name will 
>> be returned as a list, so process accordingly.
>
>
>
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python




More information about the Mod_python mailing list