Python Script REQUEST namespace not found.
Hi, I'm trying to write my first python script by passing parameter through the REQUEST object as following: --------------------------- In the Python Script: Parameter: name="world" return "Hello %s" %name ------------------------ in my DTML-Document: <dtml-call "REQUEST.set('name', 'John')"> <dtml-var hello> -------------------------- In this case, I set the name to 'John' in the REQUEST object and call 'hello' object. 'hello' object shall be able to find the 'name' as 'John', but it doesn't The final result after calling the DTML-Document is: 'hello world' Anyone have idea, why the script didn'tt lookup the REQUEST object?
H.Tan wrote:
Hi,
I'm trying to write my first python script by passing parameter through the REQUEST object as following:
--------------------------- In the Python Script:
Parameter: name="world" return "Hello %s" %name ------------------------
Here is one approach Do not set Parameter (this will come from the request object) GotName= request.other.name retrun "Hello %s" GotName This should work HTH Chetan
H.Tan writes:
I'm trying to write my first python script by passing parameter through the REQUEST object as following:
--------------------------- In the Python Script:
Parameter: name="world" return "Hello %s" %name ------------------------
in my DTML-Document:
<dtml-call "REQUEST.set('name', 'John')"> <dtml-var hello> Parameters are only magically passed into Python scripts when they are called directly from the Web (this is ZPublisher magic) or when they bind (--> "Bindings" tab) the DTML namespace (this is DTML magic).
When possible, you should not rely on magic, but pass the parameters explicitly: <dtml-var expr="hello('John')"> Dieter
this is interesting to know that there is a magic around ZPublisher. But I believe, there must be a definite answer to get Python Script reading variable in REQUEST namespace. I tried using Session object and it works. Below is my code: --------------------------- DTML-document: helloDoc <dtml-call "SESSION.set('name', 'john') "> <dtml-var hello> --------------------------------- Python Script 'hello' Parameter name='world' session=context.REQUEST.SESSION l=session['name'] return "Hello %s" %l ---------------------------------- The result is: 'hello john' which is correct result. ----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "H.Tan" <htan@gmx.de> Cc: <zope@zope.org> Sent: Thursday, September 05, 2002 2:30 AM Subject: Re: [Zope] Python Script REQUEST namespace not found.
H.Tan writes:
I'm trying to write my first python script by passing parameter through the REQUEST object as following:
--------------------------- In the Python Script:
Parameter: name="world" return "Hello %s" %name ------------------------
in my DTML-Document:
<dtml-call "REQUEST.set('name', 'John')"> <dtml-var hello> Parameters are only magically passed into Python scripts when they are called directly from the Web (this is ZPublisher magic) or when they bind (--> "Bindings" tab) the DTML namespace (this is DTML magic).
When possible, you should not rely on magic, but pass the parameters explicitly:
<dtml-var expr="hello('John')">
Dieter
H.Tan writes:
this is interesting to know that there is a magic around ZPublisher. But I believe, there must be a definite answer to get Python Script reading variable in REQUEST namespace. You already have been told how to read REQUEST variables in a Python script. It is very easy, just usually not automatic.
Dieter
participants (3)
-
Chetan Kumar -
Dieter Maurer -
H.Tan