【问题标题】:Flask not getting cookies烧瓶没有得到饼干
【发布时间】: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


    【解决方案1】:

    您将max_age 设置为1 秒,您的cookie 刚刚过期,请尝试增加max_age 的值

    【讨论】:

    猜你喜欢
    • 2016-04-19
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    • 2021-02-16
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 2019-02-10
    相关资源
    最近更新 更多