2015-10-14 38 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__後衛外部。