[ZPT] Pass parameters via RESPONSE.redirect

Geir Bækholt Geir Bækholt
Thu, 12 Dec 2002 21:19:27 +0100


Hello Rainer, 

Thursday, December 12, 2002, 8:45:38 PM, you wrote:

> Hi,

> i'd like to present a list of objects on a site and the user should
> have the option to change the parameters which define the list (e.g.
> display all obj from a certain author). On top of the site there's a
> form which passes the parameters to a script (author='bla') and the
> script redirects to that page.
> Looks like this:

> <form>: author -> select box
>         action -> script, which gets authorname
> </form>
> <div tal:define="author request/author | python:'Mad Max'">
> list items
> </div>

> How do i pass the parameters given to the script to the page via the redirect?
> When i try to add the author to the request in the script like
> request.set('author',author)
> it doesn't show up in the request in the redirected page.

> In DTML there's something like passing keyword arguments to a response
> page which show up in request/options.
> Is there something similar in ZPT?

a RESPONSE.redirect actually just asks the client(browser) to go to
another page. As the client itself requests the new page, you cannot
pass paramteres directly , but have to use one of these tricks.
REQUEST only lives within a single HTTP-request, and redirect forces a
new one...

1 . use cookies
2 . use sessions
3 . pass parameters in the redirect url
    REQUEST.RESPONSE.redirect('url/to/zpt?author=%s' %(author,))

4. The best solution IMHO, is to avoid redirecting alltogether , but
just returning a zpt instead of redirecting to it:

   in a script(python) , you can do :

   return context.theZPTyoutalkedabout(author=author)

author should then be accessible as options/author (not
request/options/author)
   
-- 
Geir Bækholt        geir@funcom.com
Tools/HCI-developer
Tools/Billing - Product Operations
Funcom Oslo