0

I'm trying to deploy a simple flask app. Then I choose gunicorn and nginx. But when I tryed the app just with gunicorn running, the follow exception appears:

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"])
davidism
  • 121,510
  • 29
  • 395
  • 339
urb
  • 924
  • 1
  • 13
  • 28

1 Answers1

5

The whole point of the __name__ guard is so that code won't execute when the module is imported. WSGI servers import your module and uses the Flask app callable, so that code doesn't get executed. Move the config outside of the __name__ guard.

davidism
  • 121,510
  • 29
  • 395
  • 339