Some of the information here may be outdated, please check the book instead

Web2py uses a Python's SimpleCookie objects for storing cookies in request.cookies and setting them in response.cookies.

To set a cookie which expires in 1 day use:

response.cookies['name'] = value response.cookies['expires'] = 3600 * 24

If you want the cookie to be accessible from other functions/controllers, you need to set the path of the cookie:

response.cookies['name']['path'] = '/'

Of course you can set it to something else, and then it will be only accessible from that path or below.

You can then access your cookie like this:


If the cookie is not set, then `request.cookies['name'] will not be set, so you might want to check before accessing it:

if request.cookies.has_key ('name'): #can use cookie

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.