[mod_python] util.Fieldstorage and form

sandip sandipm at talentica.com
Thu Sep 21 09:17:12 EDT 2006


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
> 



More information about the Mod_python mailing list