gpt4 book ai didi

python - 尝试闪烁消息会引发异常

转载 作者:行者123 更新时间:2023-11-30 21:49:52 24 4
gpt4 key购买 nike

我想使用 flash 显示消息,但这样做会引发异常。下面的代码演示了该错误,如果删除对 flash 的调用,则可以正常工作。如何修复此错误?

from flask import Flask, flash

app = Flask(__name__)

@app.route('/')
def index():
flash('Entered')
return 'Completed'

app.run(debug=True)
RuntimeError: the session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.

最佳答案

正如错误所示,您尚未设置 key ,因此 session 不可用。 session 依赖 key 对 cookie 进行签名以防止篡改。消息闪烁依赖于 session 。

设置 SECRET_KEY 配置项来修复此错误。

# set as part of the config
SECRET_KEY = 'many random bytes'

# or set directly on the app
app.secret_key = 'many random bytes'

关于python - 尝试闪烁消息会引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30223379/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com