我正在为我的网站制作后端,它需要烧瓶设置cookie。当我设置 cookie 时,它工作正常,但是当我尝试获取它们时,request.cookies.get('name')它返回 None 。我尝试返回request.cookies,那里只有我的 GA cookie,而不是我设置的。难道我做错了什么?这是我的代码:
@app.route("/setcookie", methods=["GET", "POST"])
def setcookie():
resp = make_response(render_template("index.html"))
resp.set_cookie("authToken", "testestestestestestes", max_age=1)
return resp
@app.route("/getcookie", methods=["GET" ,"POST"])
def getcookie():
return request.cookies
index.html形式:
<form action="/setcookie" method="POST">
<button type="submit">Set</button>
</form>
<form action="/getcookie" method="POST">
<button type="submit">Get</button>
</form>
我将 GA cookie 与我设置的 cookie 进行了比较,唯一的区别是名称和值,这让我更加困惑。我也不需要在前端对它们做任何事情,它们只需要由烧瓶读取。有人可以帮忙吗?谢谢
九州编程
相关分类