【发布时间】:2020-09-28 01:37:19
【问题描述】:
我正在为我的网站制作后端,它需要烧瓶设置 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 进行了比较,唯一的区别是名称和值,这让我更加困惑。我也不需要在前端对它们做任何事情,它们只需要被烧瓶读取。有人可以帮忙吗?谢谢
【问题讨论】:
标签: python flask cookies backend