[Welcome] [TitleIndex] [WordIndex

Problem

From one Quixote handler, you want to send the user to a different URL.

Solution

Use the redirect() function from the quixote package. It sets the proper header to redirect the client and returns a small HTML page with a link to the new location in case the client doesn't follow redirects properly.

from quixote import redirect
...
return redirect("http://www.example.com")

The method passes the current URL and the string argument you provide to Python's urlparse.urljoin() function, so you can use relative paths.

return redirect("../catalog")

You can also use the get_path(N) function to get the current path with N components removed. If the current path is "/abc/def/", the following code will redirect to "/abc/":

from quixote import redirect, get_path
...
return redirect(get_path(1) + '/')


CategoryCookbook


2010-09-22 22:14