Jimmy Jimmy - 1 year ago 158
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download