[mod_python] Newbie question: Fieldstorage is empty in the second handler

Daniel West dwmp at opti.cgi.net
Fri Jan 9 10:41:18 EST 2004


The req object is just a python object.  You can assign any new members you 
want to it and they will remain throughout Apache's request handling 
process.   So in your authenhandler() do this:

req.form = FieldStorage(req)

Then when you need to get your variables in handler() just do this:

path = req.form['PATH'].value


-Dan



At 05:29 PM 1/9/2004 +0100, you wrote:
>Hello Daniel,
>
>
>>You're probably creating a FieldStorage in authenhandler() and then 
>>recreating the FieldStorage in your handler().  You're using a POST 
>>request so the when FieldStorage is created it reads the fields from the 
>>body of the request (GET requests put the variables in the header) via 
>>the req.read() method. Once you've read the body of the of a request, it 
>>cannot be read again.  So when your second FieldStorage is created, there 
>>is no body request data left to be read.
>>As it turns out, the req object you get in authenhandler() and handler() 
>>is the same object.
>
>
>It is just as you said: I used a POST request and called FieldStorage in 
>authenhandler() and handler().
>
>>So when you create your first FieldStorage in authenhandler(), assign it 
>>to the req object and it will be available in your handler() function 
>>without having to recreate it again.
>
>How can you assign the FieldStorage to a req object ? I could not find any 
>variable it could be assigned to in the docu.
>
>
>
>Arno
>
>
>
>>-Dan
>>
>>
>>At 02:12 PM 1/9/2004 +0100, you wrote:
>>
>>>Hello,
>>>
>>>I have just started using mod_pyhon and have come to a problem I cannot 
>>>find an solution for:
>>>
>>>In my html file there is a hidden input named PATH:
>>>
>>><FORM method="post" action="/qwer/eval.py">
>>><INPUT type="hidden" name="PATH" value="/mhanel/physik/1b/2002-11-24"/>
>>>...
>>></FORM>
>>>
>>>When the form is submitted the PATH variable reaches the 
>>>authenhandler(req) which I can give out to a file:
>>>
>>>PATH=/schools/HTL-Imst/innenausbau/teachers/mhanel/physik/1b/2002-11-24
>>>
>>>but after that it does not reach the following handler(req) function. It 
>>>always raises an KeyError since the PATH variable does not exist in this 
>>>function anymore !
>>>Can anyone point me to the right direction ?
>>>
>>>
>>>
>>>cheers,
>>>
>>>Arno
>>
>>_______________________________________________
>>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