Differences between revisions 1 and 2
Revision 1 as of 2005-06-11 13:42:53
Size: 666
Editor: ZoomQuiet
Comment:
Revision 2 as of 2009-12-25 07:14:54
Size: 666
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Problem

You wish to check if the user has any cookies set from previous interactions with your application.

Solution

To retrieve a cookie with a given name, use the HTTPRequest.get_cookie() method.

     login_time = request.get_cookie('login_time')

get_cookie() returns a string containing the cookie's value; if no such cookie exists, get_cookie() returns None. You can also specify a different default value:

    login_time = int(request.get_cookie('login_time', time.time()))

Discussion

See CookieSecurity for a discussion of security considerations related to cookies.


CategoryCookbook

QuixoteCookbook/ReadingCookies (last edited 2009-12-25 07:14:54 by localhost)