ibrewster
ibrewster

Reputation: 3632

Python/Cherrypy: set cookie on redirect

I am trying to figure out how to set a cookie just before a redirect from Cherrypy. My situation is this:

The way my login system works is that after a successful login, the user is redirected to whatever page they were trying to access before logging in, or the default page. Technically they are redirected to a different domain, since the login page is secure while the rest of the site is not, but it is all on the same site/hostname. Redirection is accomplished by raising a cherrypy.HTTPRedirect(). I would like to set the cookie either just before or just after the redirect, but when I tried setting cherrypy.response.cookie[<tag>]=<value> before the redirect, it does nothing. At the moment I have resorted to setting the cookie in every index page of my site, in the hopes that that will cover most of the redirect options, but I don't like this solution. Is there a better option, and if so what?

Upvotes: 2

Views: 971

Answers (1)

ibrewster
ibrewster

Reputation: 3632

To answer my own question: It would appear that if I add cherrypy.response.cookie[<tag>]['path'] = '/' after setting the cookie value, it works as desired.

Upvotes: 2

Related Questions