[mod_python] clarity on request.form

Graham Dumpleton grahamd at dscpl.com.au
Tue May 23 23:17:45 EDT 2006


David Bear wrote ..
> >From the manual, I don't understand the following statement:
> '''
> 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.
> '''
> 
> I've been using publisher as a dispatcher to select the next psp to
> serve. Does the above statement imply that I cannot do this?  Where is
> Request.form define? is Request not the same as req?

Add a argument called "req" to your published function and then
access "req.form".

  def index(req):
    form = req.form

Unfortunately PSP doesn't play too nice with publisher as far as
form creation and will create its own if you access "form" from
inside PSP page. If request is a GET request, although redundantly
created, the form will still work. If a POST request though, there
will be no fields as publisher already consumed it.

The work around for this is to use something like:

    page = psp.PSP(.....)
    page.run({"form": form})
    ...

There was discussion about having PSP understand convention of req.form
being populated by publisher and use it if it exists, but no consensus
was reached on whether it was a good idea or not.

Graham


More information about the Mod_python mailing list