request是请求数据,(主要是get、post后端怎么获取数据)
response是响应(主要是cookie、session怎么在后端获取)
前端代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>set cookie</h1>
</body>
</html>
后端
from flask import Flask,render_template,make_response,request
app = Flask(__name__)
@app.route('/')
def index():
print(request.cookies.get('name'))
return make_response(render_template('07_index.html'))
@app.route('/set_cookie')
def set_cookie():
response = make_response(render_template('07_index.html'))
response.set_cookie('name','laowang',max_age=10)
return response
@app.route('/del_cookie')
def del_cookie():
response = make_response('删除cookie')
response.delete_cookie("name")
return response
if __name__ == '__main__':
app.run(debug=True)
在浏览器中就可以看到了