[mod_python] util.Fieldstorage and form

Graham Dumpleton grahamd at dscpl.com.au
Mon Sep 25 07:36:37 EDT 2006


Your questions may in part be answered by:

   http://issues.apache.org/jira/browse/MODPYTHON-38

If FieldStorage object is constructed twice, on the second time  
round, it
will only be able to provide access to form fields which are part of the
query string of the URL itself and not any field embedded as multipart
form data within the content of the POST request. This was what Jim
was getting as except that he didn't mention case where mix of query
string and multipart form parameters used.

What is not clear from your message is whether you are doing absolutely
everything within a self contained PSP page, or whether you are actually
using a wrapper around it in the form of a custom handler or a handler
such as mod_python.publisher.

If you are wrapping PSP stuff on mod_python.publisher functions, you
actually need to pass in "form" something like:

     settings = {}
     ...
     settings.update({"form":req.form})
     template = psp.PSP(req,filename=path,vars=settings)
     template.run()

In mod_python 3.3, this will no longer be necessary as PSP has been
changed to  use req.form which may be inherited from a custom handler
which has already created it and stored it as that named attribute of  
the
request object.

Can you be clearer about whether you are using mix of query string
parameters and multipart form parameters within content of request,
and clarify whether you are using PSP only or in conjunction with
another handler.

Posting an actual small working example of what you are talking about
would be good, as then we don't need to guess.

Graham

On 21/09/2006, at 11:17 PM, sandip wrote:

> Thanks Jim. This explains the puzzle.
> but form['filefield'] doesn't work for accessing file data.
> how to use form to access file data? or Is form being implemented  
> partially in mod_python?
>
> thanks
> sandip
>
>
> ----- Original Message ----- From: "Jim Gallacher"  
> <jpg at jgassociates.ca>
> To: "sandip" <sandip.more at gmail.com>
> Cc: <mod_python at modpython.org>
> Sent: Thursday, September 21, 2006 6:02 PM
> Subject: Re: [mod_python] util.Fieldstorage and form
>
>
>> sandip wrote:
>>> Hi all,
>>>    Other day i was trying to build upload functionality in psp. I  
>>> am handling form(method: POST) submission in psp.
>>> this form contain a hidden element and  a element of type file  
>>> for upload.
>>> I observed certain things. When I use form['field'] to access  
>>> value of hidden form element,and in same code
>>> if I use FieldStorage(req) to get the attributes of uploaded  
>>> file. I can't access file attributes.
>>>
>>> but if I use only FieldStorage to access all the elements of  
>>> form, I could access it.
>>>
>>> so why can't I  use both form and FieldStorage in same code?
>>
>> The form you see in psp is actually a FieldStorage instance which  
>> is automatically created when the psp parse encounters mention of  
>> the form variable.
>>
>> FieldStorage may only be called once per request, as it consumes  
>> the request body. Wnen it is called a second time, there is  
>> nothing left to read.
>>
>> The usual solution is to store a reference to the form in your  
>> request object, and pass that around to any functions that need it.
>>
>> <%
>>   stuff = form['stuff']
>>   req.form = form
>> %>
>>
>> You'll then be able to access the form in code outside of the psp  
>> page.
>>
>> Jim
>
> _______________________________________________
> 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