Jimmy Jimmy - 2 months ago 11
Python Question

Check for a cookie with Python Flask

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

country
) with this Flask call.

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


How can I tell if the cookie exists?

Answer

request.cookies is a dict, so:

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