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)