我想使用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.
答案 0 :(得分:3)
如错误所示,您尚未设置密钥,因此会话不可用。该会话依赖于密钥来签署cookie以防止篡改。消息闪烁依赖于会话。
设置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'
答案 1 :(得分:0)
在您的run.py文件中
complete yes_no
1 HmOsw1WtXRxRfZ5tE1Jx Yes
2 tgdzehXaH8xtgn0TkCJD Yes
3 7PPM87DSFr1Qn6YC7ktM Yes
4 e4NGoRoonQkch*SCMbL6 No
5 EfPm5QztsA7eKeJAm4SV Yes
6 aJTxTtubO8vH2wi7XxZO Yes