Django: Set cookie expiry time to one day

0 Comments

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

1.d = datetime.datetime.now() + datetime.timedelta(days = 1)
2.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