[Zope] Passing a variable to RESPONSE.redirect

J Cameron Cooper zope-l at jcameroncooper.com
Fri Jul 15 11:49:00 EDT 2005


Asad Habib wrote:
> Is it possible to pass a variable to RESPONSE.redirect or does the page
> name have to be a literal string? I was unable to pass in a variable via
> the REQUEST object (i.e. REQUEST.get('pageName')) or the SESSION attribute
> of the REQUEST object (i.e. REQUEST.SESSION.get('pageName')). Any help
> would be appreciated. Thanks.

How do you mean "unable"? That's not a very good problem description.

RESPONSE.redirect is simply a Python method, and it will take any string 
you can manage, no matter where it comes from. In fact, I think it would 
be very difficult to do otherwise.

You must, of course, pass the value of a variable, and not the variable 
itself. None of the following pose any problem::

  REQUEST.RESPONSE.redirect("http://plone.org")

  url = "http://plone.org"
  REQUEST.RESPONSE.redirect(url)

  def redir():
    return "http://plone.org"
  REQUEST.RESPONSE.redirect(redir())

  urls = {}
  urls['plone'] = "http://plone.org"
  REQUEST.RESPONSE.redirect(urls['plone'])

  REQUEST.RESPONSE.redirect(urls.get('plone', "/"))

In fact, they should all work identically.

            --jcc
-- 
"Building Websites with Plone"
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com


More information about the Zope mailing list