Check for a cookie with Python Flask Check for a cookie with Python Flask python python

Check for a cookie with Python Flask


request.cookies is a dict, so:

from flask import requestif 'country' in request.cookies:    # do somethingelse:    # do something else


request.cookies.get('my_cookie')

should have worked. If it didn't work, you may not have access to the request object when you call this line.

Try importing flask at the top

import flask

then call

cookie = flask.request.cookies.get('my_cookie')

If the cookies exists, it will get assigned to cookie and if not then cookie will equal None