[Zope] Newbie: passing data from scripts to ZPT
Paul Winkler
pw_lists at slinkp.com
Mon Nov 3 14:36:55 EST 2003
On Mon, Nov 03, 2003 at 03:44:19PM -0300, Franco M. Luque wrote:
> Hello. I want a Python Script that redirects to a ZPT, so that the ZPT can
> see information generated by the Script. I don't want this information to
> persist along all the session. Is there any way to do this?
>
> I tried saving the data in the REQUEST object, but it seems that the
> redirection generates a new REQUEST object for the ZPT and forgets the
> other one.
That is correct. That's just how redirects work.
You have several options, each with advantages and disadvantages:
1) redirect from the script to a URL that includes the necessary
information as parameters:
context.REQUEST.RESPONSE.redirect("list_html?foo=bar&blah=23")
... you are limited by the length of the query string which
cannot grow indefinitely. I forget what the limits are.
2) don't redirect. Call the script from the zpt.
<html>
<body>
<p tal:content="context/foo_script"> </p>
</body>
</html>
This is my preferred solution unless the script must
direct the user to several templates in different cases.
3) don't redirect. Call the zpt from the script:
return context.list_html(foo="bar", blah=23)
... parameters can be accessed in the page template in the "options" namespace.
This is a fine solution except that the URL displayed is that of the script
rather than that of the template. You must decide whether this is a problem.
Some zopistas seem to have aesthetic objections to calling templates from scripts.
It's transparent to the user so I don't see a problem.
P.S. your english is very good.
--
Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's META APACHE!
(random hero from isometric.spaceninja.com)
More information about the Zope
mailing list