Flask: How to remove cookies?

后端 未结 3 1681
走了就别回头了
走了就别回头了 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条回答
  •  走了就别回头了
    2021-01-03 18:23

    There's no HTTP header for deleting a cookie. Traditionally you just set the cookie to a dummy value with an expiration date in the past, so it immediately expires.

    resp.set_cookie('sessionID', '', expires=0)
    

    This will set the session id cookie to an empty string that expires at unixtime 0, which is almost certainly in the past.

提交回复
热议问题