标签:返回 delete 简单 str 就会 设置 浏览器 ons out
@app.route(‘/set_cookie‘) def set_cookie(): response=make_response(‘Hello World‘); response.set_cookie(‘Name‘,‘Hyman‘) return response
outdate=datetime.datetime.today() + datetime.timedelta(days=30) response.set_cookie(‘Name‘,‘Hyman‘,expires=outdate)
@app.route(‘/get_cookie‘) def get_cookie(): name=request.cookies.get(‘Name‘) return name
test.html:
<h1>My name is {{request.cookies.get(‘Name‘)}}</h1>
@app.route(‘/get_template‘) def get_template(): return render_template(‘test.html‘)
(1) 可以通过在浏览器中设置来清除cookie.
(2) 使用Response的set_cookie进行清除
@app.route(‘/del_cookie‘) def del_cookie(): response=make_response(‘delete cookie‘) response.set_cookie(‘Name‘,‘‘,expires=0) return response
(3)使用Response的 delete_cookie方法.
@app.route(‘/del_cookie2‘) def del_cookie2(): response=make_response(‘delete cookie2‘) response.delete_cookie(‘Name‘) return response
标签:返回 delete 简单 str 就会 设置 浏览器 ons out
原文地址:https://www.cnblogs.com/wuzaipei/p/9901236.html