Flask: How to remove cookies?

后端 未结 3 1700
走了就别回头了
走了就别回头了 2021-01-03 17:43

I set cookies with the code suggested in the docs:

from flask import make_response

@app.route(\'/\')
def index():
    resp = make_response(render_template(.         


        
3条回答
  •  旧时难觅i
    2021-01-03 18:25

    You need to set the cookie with an expiry that's in the past.

    resp = make_response(render_template(...))
    resp.set_cookie('username', expires=0)
    return resp
    

    By the way, I hope you don't actually expect that username cookie to be safe. Because it's not. The user can put anything he wants in there. The solution is usually to use the Flask session which uses a signed cookie that cannot be modified by the user.

提交回复
热议问题