[SPAM] Re: [mod_python] accessing a 'POST'ed string ?

Dave Britton dave at davebritton.com
Sun Jan 18 08:34:15 EST 2009


"I cant find out how
> to access the  posted string from mod python.


Dave,
I need to do that a lot. The Request object has the form object which has a
list (named "list") of Fields that are filled with the cgi posted name-value
pairs as Field.name and Field.value. So req.form.list gives you this list to
use. I use this code:
def index(req):
  cgi={fieldname1:initialvalue1, fieldname2:initialvalue2...}
  for i in req.form.list: cgi[i.name]=i.value

Now I can access all my passed in posted data as cgi[fieldname]. Don't leave
out the initialization in case the user doesn't fill out a field or a
checkbox isn't checked, as req.form.list does not receive empty name-value
pairs at all, causing a key error if you reference cgi[missingfield].

-Dave
----- Original Message -----
From: "dave selby" <dave6502 at googlemail.com>
To: <mod_python at modpython.org>
Sent: Saturday, January 17, 2009 3:30 PM
Subject: [mod_python] accessing a 'POST'ed string ?


> Hi all,
>
> I have been using mod python for a while with 'GET', no problem,
> accessing values with
> func = req.form['val'] since I only need to pass one value.
>
> However I now need to use 'POST' since I have a lot bigger data
> 'blob'. I post it from the browsers javascript but I cant find out how
> to access the  posted string from mod python.
>
> I have googled and routed around but have not had any luck
>
> Can anyone help ?
>
> Cheers
>
> Dave
>
> --
>
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
> _______________________________________________
> 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