[mod_python] FieldStorage and POST?

Graham Dumpleton grahamd at dscpl.com.au
Tue Jul 4 18:48:24 EDT 2006


Please keep followups on the mailing list.

smilelover at centrum.cz wrote ..
> Dne Wed, 05 Jul 2006 00:10:20 +0200 napsal(a) Graham Dumpleton  
> <grahamd at dscpl.com.au> následující zprávu:
> 
> > smilelover at centrum.cz wrote ..
> >> Hi,
> >> I can't make FieldStorage instance give me my POST arguments.
> >> When I send my form data through GET, FieldStorage contains them. But
> >> when
> >> I use POST and then do:
> >>
> >> req.write(util.FieldStorage(req).list[0].value)
> >>
> >> Python tells me "list index out of range"
> >> I have googled quite a lot and found bits of information about problems
> >> with POST and FieldStorage, but nothing that could help me figure out
> >> WHERE the POST data are.
> >>
> >> Thanks in advance for every hint.
> >
> > Are you doing this from inside a function published using
> > mod_python.publisher, as opposed to a basic handler? If
> > you are doing this from inside a function published using
> > mod_python.publisher then it will already have consumed
> > the POST content of the request.
> >
> > Thus, show more complete code for the function this is being
> > done in and show the Apache configuration you are using to
> > trigger that function. Also show what URL you are using and
> > how that relates to the names of your handler files or whether
> > the URL matches to the directory itself.
> >
> > If you are using mod_python.publisher, the form parameters
> > are supplied to argument to function of same name. The raw
> > FieldStorage object can also be accessed as req.form, you do not
> > need to create it yourself.
> >
> > Graham
> 
> Yes, I'm working with publisher. I have a module "admin.py" that contains
> several funcs - it's a small CMS. On one page I choose articles I want
> to  
> delete and submit the form to the following function:
> 
> def delete(req):
> 	sess = Session.Session(req)
> 	if not sess.has_key('login_name'):
> 		util.redirect(req, 'index?unauth=1')
> 	
> 	req.content_type = 'text/html'
> 	req.write(util.FieldStorage(req).list[0].value) # this is a line just
> to  
> find out what's happening
> 	return
> 
> My .htaccess is pretty simple:
> SetHandler mod_python
> PythonHandler mod_python.publisher
> PythonDebug On
> 
> Yes I know arguments are passed thru function argumens, but the count of
> my args is dynamic...should I just use **params?

If the number of form arguments can vary and not sensible to have default
values of None if a function argument is used, the using '**params' is
generally an acceptable way of doing it.

> Or is it better to do it all through req.form? (I don't see it in the 
> Request object docs thou)

It is put there by mod_python.publisher handler.

Read:

  http://www.modpython.org/live/current/doc-html/node94.html

  Since a FieldStorage can only be instantiated once per request, one must
  not attempt to instantiate FieldStorage when using the Publisher handler
  and should use Request.form instead.

Graham


More information about the Mod_python mailing list