[mod_python] Redirect

Graham Dumpleton grahamd at dscpl.com.au
Mon Jan 8 16:12:11 EST 2007

g.farina at pharaondev.com wrote ..
> Hi
> I have an autentication script and I'd like the browser to redirect to
> a
> specific http location if the authentication fails.
> There is a way to do this redirection using mod_python internals ?


  from mod_python import util

  util.redirect(req, 'http://some-host/....')



Note though that if using mod_python < 3.3, you will hit this problem
if trying to do it from an authentication handler.


Thus, if on an older version of mod_python you should look at how the
redirect function is implemented and just do the same thing yourself,
ensuring you use DONE and not OK.

If using mod_python 3.3, you might also look at the req.construct_url()
method as a means of properly constructing the target URL for your
redirect. See:


Version 3.3.0b is available from:


Although announced, the mod_python site hasn't been updated to mention it.


More information about the Mod_python mailing list