[mod_python] Redirection with the Location Header and publisher handler

Robert Sherwood foofboy at speakeasy.net
Thu Jan 10 11:31:42 EST 2002


I think you're looking for this:

req.content_type = 'text/html'
req.err_headers_out['Refresh'] = '3;http://usl/to/new/location'
#Redirect after 3 Seconds
req.send_http_header()
return apache.HTTP_MOVED_PERMANENTLY

Rob


On Thu, 2002-01-10 at 07:58, Jonathan Gardner wrote:
> I read through the documentation a few times. I am not sure how to do this.
> 
> What I want to do is to receive a hit to a function, and then have that 
> function redirect the browser to another location.
> 
> For instance, I have a function that will present a form for adding an entry 
> into a database. When the user hits "submit", I want to have the function 
> that inserts the stuff into the db called, and then have it redirect the 
> browser back to the original page with a status message of the sort "Row 
> added" or "Cannot enter duplicate items in a unique column" or whatnot.
> 
> I know that there are two ways of doing this:
> 
> 1) Sending some HTML that will redirect it to the appropriate location. This 
> is a non-smooth solution.
> 
> 2) Sending the Location header with the new location.
> 
>  (It's been a few months since I have done this, and I don't have the example 
> code, plus it was done in mod_perl... this is three strikes against my 
> memory. I could be wrong).
> 
> I've tried something like this: (Remember, I am using publisher as the 
> handler)
> 
> def myfunc(req):
> 	req.headers_out['Location']="http://url/to/new/location"
> 	req.send_http_headers()
> 	return apache.OK
> 
> and I've tried a bunch of variations on this theme... but nothing seems to 
> work write. Can someone give me a pointer or let me know where I'm confused?
> 
> Of course, I've read all the documentation, but nothing seems to help.
> 
> Jonathan
> 
> 
> _______________________________________________
> 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