[mod_python] HTTP response codes

Gregory (Grisha) Trubetskoy grisha at modpython.org
Mon Dec 31 17:37:01 EST 2001

By returning an error code, you're asking Apache to deal with your error.
Apache will then display a stock error page, and will send error headers
(req.err_headers_out instead of req.headers_out), which is why you didn't
see your header amongst them.

What you want to do instead is handle everything yourself, and then let
Apache know it's done by returning apache.OK.

Something like this should work (this is from the FAQ, btw):

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


On Mon, 31 Dec 2001, Clarence Gardner wrote:

> I'm not seeing a way to do much with the response code. In particular,
> I want to do a redirection, which requires a 3xx response and a Location
> header.
> If I just return HTTP_MOVED_PERMANENTLY, the server sends an HTML
> document containing an empty link, with a status of 301. If I set
> the header, call send_http_header, and then return that status, I
> get the same HTML, but with a 200 status (and my Location header
> isn't included anyway).
> Have I missed something?
> Thanks.
> --
> Clarence Gardner
> Software Engineer
> NetLojix Communications
> clarence at netlojix.com
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list