Jimmy Jimmy - 1 year ago 96
Python Question

Check for a cookie with Python Flask

I would like to get a cookie (e.g.

) with this Flask call.

data = request.cookies.get("country")

How can I tell if the cookie exists?

Answer Source

request.cookies is a dict, so:

if 'country' in request.cookies:
    # do something
    # do something else