Django: Set cookie expiry time to one day

To set browser cookies in Django that automatically expire in the specified time, use the following snippet:

d = datetime.datetime.now() + datetime.timedelta(days = 1)
response.set_cookie('something', value = 50, expires = d.strftime("%a, %d-%b-%Y %H:%M:%S GMT"))
 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog