[mod_python] Redirection with the Location Header and publisher handler

Jonathan Gardner jgardn at alumni.washington.edu
Thu Jan 10 21:58:28 EST 2002

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 

def myfunc(req):
	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.


More information about the Mod_python mailing list