Setting the request object in Zope

One of those “note-to-self” type posts, but this is something I always have problems remembering for some reason.

It’s quite easy to set a property in the request object using request.set(’key’, ‘value’) in your Python script. However, if you then redirect to another page this property is lost. What you need to do is something along these lines:


request = container.REQUEST
RESPONSE = request.RESPONSE
request.set("my_new_key", "my_new_value")
response = context.id_of_page_to_call(request)
return response

You can then use this new request object property in the page you “redirect” to. The URL won’t change, i.e. if the script you’re doing all this in is called something like “myscript”, “myscript” will remain in the URL after the new page “id_of_page_to_call” has been called.

Tags: blog-post, plone, zope.

Archives