1. Problem

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

2. Solution

Use the redirect() method of HTTPRequest. 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.

return request.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 request.redirect("../catalog")

You can also use the HTTPRequest.get_url(N) method to get the current URL with N components removed. If the current URL is "http://example.com/abc/def/", the following code will redirect to "http://example.com/abc":

return request.redirect(request.get_url(1))


CategoryCookbook