[mod_python] Servlets, cookies and redirect

Daniel Popowich dpopowich at comcast.net
Fri Sep 3 16:08:05 EDT 2004

MJR writes:
> with mod_python servlets, I am trying to set cookie and redirect with
> following code:
> ===========================================================
> class set(HTMLPage):
>     def prep(self):
>         HTMLPage.prep(self)
>         minute=time()+60
>         self.add_cookie('test', 'test_value', expires=minute)
>         self.external_redirect(view)
> ===========================================================
> With external_redirect cookie is not set, without redirect it works fine
> (cookie set). I've obviously missed something... what is a proper way to do
> this?

As was discussed in this thread, the Servlet.add_cookie() method is a
wrapper around mod_python.Cookie.add_cookie().  This is by design
(just like building on top of mod_python.Session) as I have no
interest in redesigning the wheel.  If the Cookie module ever exposes
options to set "normal" vs. "error" headers, I'll propagate them to
Servlet, but otherwise I don't want to touch this.

Of course, you're always free to subclass and add the functionality.
There in lies the joy of OO programming.

Daniel Popowich

More information about the Mod_python mailing list