[Zope] Python access to dtml-let vars
John Hunter
jdhunter@ace.bsd.uchicago.edu
Tue, 14 May 2002 09:14:14 -0500
>>>>> "Charlie" == Charlie Reiman <creiman@kefta.com> writes:
Charlie> I want to have a DTML method that has this in it:
Charlie> <dtml-let var1="'avalue'"> <dtml-var myscript>
Charlie> </dtml-let>
Charlie> And a python script call myscript that does something
Charlie> like:
Charlie> print mysterious_voodoo.getitem('var1')
Charlie> The right text for mysterious_voodoo eludes me. How do I
Charlie> access dtml-let set variables from a python script
Charlie> context? Is it possible?
There are two kinds of voodoo that will work for you here. The
easiest is simply to pass the argument to the python script as a
parameter. If you add var1 to the 'Parameter List' under the 'Edit' tab
of the python script, then you can do
<dtml-var expr="myscript(var1=var1)">
Alternatively, you can set the REQUEST header
<dtml-call expr="REQUEST.set('var1', var1)">
and then in python
REQUEST = container.REQUEST
RESPONSE = REQUEST.RESPONSE
var1 = REQUEST.get('var1')
You said you were concerned about security: both of these approaches
are less transparent to the user than passing them by the CGI
myscript?var1=someval, but determined or savvy users can still
read/edit the REQUEST headers, so don't be lulled into a false sense
of security.
Cheers,
John Hunter