secret key not set in flask session, using the Flask-Session extension

前端 未结 3 993
南方客
南方客 2020-12-04 17:26

Right now I am using a flask 3rd party library Flask-Session and I am having no luck getting a session working.

When I connect to my site, I get the following error:

3条回答
  •  青春惊慌失措
    2020-12-04 18:04

    Set the secret key outside of if __name__ == '__main__':

    app.py:

    from flask import Flask, session
    
    app = Flask(__name__)
    app.secret_key = "super secret key"
    
    @app.route("/")
    ...
    
    if __name__ == '__main__':
        app.debug = True
        app.run()
    

    When you start your app by running flask run the if __name__ == '__main__': block gets skipped. If you don't want to skip it, run with python app.py.

提交回复
热议问题