[mod_python] Re: Mod_python Digest, Vol 25, Issue 6

Barry Pearce barry.pearce at copyrightwitness.net
Wed Apr 6 17:10:49 EDT 2005


Hi,

> I'm using the cgihandler with mod_python3.0.3, Apache2.0.46 and
> python2.2.3. I would like to know how I'm meant do url redirections.
> My code looks something like this:
> 
> try: 
>      .....
>       print "Location: %s\n" % url 
> except:
>         pass
> which works as a regular CGI script (ie. it redirects to the specified
> url). It's definitely not hitting the exception and  but redirection
> isn't happening either.

Shouldn't that be a header? Set you want to use the methods to set it as 
a header. Alternatively you can do a server-side redirect using

request.internal_redirect('/my_page_on_this_server')

Which keeps the delivery of the page secret (allows URL masking).
Alternatively you could use

util.redirect(request, 'http://newlocation')

Which provides the more usual redirect based on http headers.

Hope this helps,
Barry


More information about the Mod_python mailing list