I need to implement the following:
How can I set cookies for 1 month?
Will the following work?
self.response.headers.add_header(
'Set-Cookie',
'credentials=%s; expires=Fri, 31-Dec-2020 23:59:59 GMT' \
% credentials.encode())
How to calculate one month from now in the required format?
You can use webapp.Response.set_cookie() method:
import datetime
self.response.set_cookie('name', 'value', expires=datetime.datetime.now(), path='/', domain='example.com')
Formatting dates for cookies is something like this:
print (datetime.datetime.now() + datetime.timedelta(weeks=4)).strftime('%a, %d %b %Y %H:%M:%S GMT')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With