[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 ?

Use:

  from mod_python import util

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

See:

  http://www.modpython.org/live/current/doc-html/pyapi-util-funcs.html

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

  http://issues.apache.org/jira/browse/MODPYTHON-140

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:

  http://www.modpython.org/live/mod_python-3.3.0b/doc-html/pyapi-mprequest-meth.html

Version 3.3.0b is available from:

  http://httpd.apache.org/modules/python-download.cgi

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

Graham


More information about the Mod_python mailing list