[Zope] useing the REQUEST variable in python scripts

Tim Zegir tim at ccx.com.au
Tue Sep 28 02:30:57 EDT 2004


Thank you,

Ill try it now :)

-----Original Message-----
From: Tino Wildenhain [mailto:tino at wildenhain.de] 
Sent: Tuesday, 28 September 2004 4:13 PM
To: Tim Zegir
Cc: zope at zope.org
Subject: Re: [Zope] useing the REQUEST variable in python scripts

Hi,

Am Di, den 28.09.2004 schrieb Tim Zegir um 6:39:
> Hi All,
> 
> I'm trying to get some form variables in a python script.
> The form variables are dynamic (grabbed from a database).
> I want to use a variable in the script (something like REQUEST[myvar]) to
> get the input values.
> But when I use that code I get a key error.
> 
> Does anyone know how to get a variable from a form with code like that?

So you have a form with different element names each time?
You access REQUEST via context.REQUEST
if you dont know if REQUEST or its sub element form
has a given key, you can use the standard python
mapping interface (see documentation for dictionary)

This for example has:
context.REQUEST.form.has_key("nameofyourvar")

which returns True if this variable has been sent

context.REQUEST.form.get("nameofyourvar",defaultvalue)

which would return the value of the form element
if sent or the defaultvalue otherwise.


HTH
Tino.




More information about the Zope mailing list