python flask not creating cookie when setting expiration -


I have this python-flask project and I need logic, if cookie does not exist, then cookie creates.

After creating cookies, I need to store cookies in a database for tracking purposes among other standards.

Here is partial of my current code:

import from import import code from render_template, request, make_response def load_cookie_config (reference): #context is a dictionary passed Gone key = 'some_key' template_name = 'some_template' cookie = request.cookies.get (key, none) if the cookie is not: guid = str (uuid.uuid4 ()) reference ['cookie_quid'] = gund rsp = make_response (Render_template (template_name, ** references)) rsp.set_cookie (key, guid) # ... insert some value in some method call db other: result = '' # .. some method call db reference ['co Okie_quid '] = Cookie RSP = Make-Repence (raidar_tamp) to get value from late (template_name, ** reference)) Return RSP

code above the task and expected Appears as cookie, although this cookie is omitted from the end of the browser session.

I need to set a cookie where after the expiration of X it will end after the browser, but when I change this line:

  rsp. Set_cookie (key, GUID)  

to

  rsp.set_cookie (key, GUID, expires = 90)  

This is not created

>

You max_age = 90 needs to be set up, or use datetime for your end:

Example:

  Import datetime Expire_date = datetim E.datetime.now () expire_date = expire_date + datetime.timedelta (day = 90) response.set_cookie (key, GUID, expires = expire_date)  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -