【问题标题】:Flask secret_key is unavailable when using Gunicorn, even though it's configured [duplicate]使用 Gunicorn 时 Flask secret_key 不可用,即使它已配置 [重复]
【发布时间】:2016-01-12 21:06:59
【问题描述】:

我正在尝试部署一个简单的烧瓶应用程序。然后我选择gunicorn和nginx。 但是当我尝试运行 gunicorn 的应用程序时,出现以下异常:

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

init.py:

if __name__ == '__main__':
    app.secret_key = config["secret-key"]
    app.run(port=config["port"], host=config["host"], debug=config["debug"])

【问题讨论】:

    标签: python flask gunicorn


    【解决方案1】:

    __name__ 保护的重点是在导入模块时代码不会执行。 WSGI 服务器导入您的模块并使用可调用的 Flask 应用程序,因此代码不会被执行。将配置移到 __name__ 保护之外。

    【讨论】:

      猜你喜欢
      • 2021-10-22
      • 2023-04-07
      • 2016-09-13
      • 2018-08-31
      • 1970-01-01
      • 2018-06-15
      • 1970-01-01
      • 2021-08-13
      • 1970-01-01
      相关资源
      最近更新 更多