2015-10-14 37 views
0

我正在尝试部署一个简单的烧瓶应用。然后我选择gunicorn和nginx。 但是当我tryed应用程序只是gunicorn运行,出现如下异常:当使用Gunicorn时,烧瓶secret_key不可用,即使它已配置

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"]) 

回答

5

__name__后卫的整点是为了让代码将不会被执行时模块已导入。 WSGI服务器导入您的模块并使用Flask应用程序可调用,以便代码不会被执行。将配置移至__name__后卫外部。