Thursday, February 14, 2008

Redirecting from mod_python

The sort of thing I'm inclined to forget:


def handler(req):
req.headers_out['location'] = 'http://www.modpython.org/'
req.status = apache.HTTP_MOVED_TEMPORARILY
req.send_http_header()
return apache.OK


Care of the mod_python FAQ.

1 comment:

Graham Dumpleton said...

You don't need 'req.send_http_header()' for mod_python 3.X, that was only required for mod_python 2.X.

You should also perhaps instead look at the mod_python.util.redirect() function instead. See 'http://www.modpython.org/live/current/doc-html/pyapi-util-funcs.html.

Finally, one should be redirecting oneself to 'www.modwsgi.org' these days and not 'www.modpython.org'. ;-)