Check for a cookie with Python Flask

前端 未结 2 378
醉话见心
醉话见心 2021-02-01 14:11

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 co

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-01 14:47

    request.cookies is a dict, so:

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

提交回复
热议问题