flask 密钥问题

RuntimeError
RuntimeError: The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.

当运行flask项目遇到这个问题。

如果有setting文件:
SECRET_KEY = 'adgg4df2g452hg245d74g4g' # 随便写
如果在当前app初始化文件__init__.py文件下:
app.config['SECRET_KEY'] = os.urandom(24)

falsk使用起来比较随性,看个人习惯添加。
但是有一点secret_key设置成os.urandom(24)这样的写法再项目中不合适,因为没次启动服务器这个值都会改变,所以所有保存的session都失效。

原文地址:https://www.cnblogs.com/lph970417/p/11558331.html