[mod_python] clarity on request.form

Jeff Hinrichs - DM&T jeffh at dundeemt.com
Wed May 24 00:14:35 EDT 2006


David,

I couldn't find a good answer via Google, so I took a peek at
publish.py and found that:
  req.form = util.FieldStorage(req, keep_blank_values=1)

Checking out the details of FieldStorage in util.py should give you
the info you need.  It's pure python so fairly straight forward.

Both are found in you site-packages/mod_python/ directory if
mod_python installed with default options, I believe.

-Jeff

On 5/23/06, David Bear <David.Bear at asu.edu> wrote:
> On Tue, May 23, 2006 at 08:31:04PM -0700, David Bear wrote:
> > On Tue, May 23, 2006 at 11:17:45PM -0400, Graham Dumpleton wrote:
> > > 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
> > >
> >
> > okay. thats what I thought I could do. however, the paragraph from the
> > manual tripped me up.
> >
> > > 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.
> >
> > So, in order to pass req.form to a psp, I would need to copy it to
> > some object? simple
> >
> >    thisform = req.form
> >    vars = thisform
> >    return psp.PSP('somepsp.html', vars)
> >
> > won't work? or will the assignment make a copy?
> >
>
> I just tried
>
>     myform = copy.deepcopy(req.form)
>
> and it failed..
>
> where is req.form documented? I'm looking for its methods.
>
> > >
> > > 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
> >
> > --
> > David Bear
> > phone:        480-965-8257
> > fax:  480-965-9189
> > College of Public Programs/ASU
> > Wilson Hall 232
> > Tempe, AZ 85287-0803
> >  "Beware the IP portfolio, everyone will be suspect of trespassing"
>
> --
> David Bear
> phone:  480-965-8257
> fax:    480-965-9189
> College of Public Programs/ASU
> Wilson Hall 232
> Tempe, AZ 85287-0803
>  "Beware the IP portfolio, everyone will be suspect of trespassing"
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


-- 
Jeff Hinrichs
Dundee Media & Technology, Inc
jeffh at dundeemt.com
402.320.0821



More information about the Mod_python mailing list