[mod_python] Returning a Apache return code

Jorey Bump list at joreybump.com
Tue Nov 30 14:25:44 EST 2004

Nick wrote:

> Note that you should almost always use 307 (moved temporarily) for a web 
> application, because 301 tells the client to always go to the new 
> location when the URL is requested without even asking for the original 
> page.  I.e., the page has moved permanently, don't look here anymore.

It depends on your needs. I'm using HTTP_SEE_OTHER in my application to 
sometimes redirect POST requests to an authentication page if the login 
has expired. This tells the agent to request the new resource with GET, 
preventing it from POSTing form data to the authentication page, which 
is not under my control (or even in my site).

> Jorey Bump wrote:
>> Golawala, Moiz M (GE Infrastructure) wrote:
>>> I have am newbie and I seems to be having a problem return a
>>> different apache return code. In my httpd.conf file I am using
>>> PythonHandler mod_python.publisher.
>>> In my index.py file.
>>> index(req): req.header_out['Location'] = "http://someurl:8080/ 
>>  > return apache.HTTP_PERMANENTLY_MOVED
>> Try this:
>> from mod_python import apache
>> index(req)
>>     status = apache.HTTP_MOVED_PERMANENTLY
>>     req.headers_out['Location'] = url
>>     req.status = status
>>     raise apache.SERVER_RETURN, status
>> More info:
>>  http://www.modpython.org/live/current/doc-html/pyapi-handler.html

More information about the Mod_python mailing list