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都失效。

相关文章:

  • 2021-08-24
  • 2022-12-23
  • 2021-11-21
  • 2021-09-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2021-06-11
  • 2022-12-23
  • 2022-01-28
  • 2021-10-25
相关资源
相似解决方案