Sometimes, we want to fix secret key not set in Python Flask session, using the Flask-Session extension.
In this article, we’ll look at how to fix secret key not set in Python Flask session, using the Flask-Session extension.
How to fix secret key not set in Python Flask session, using the Flask-Session extension?
To fix secret key not set in Python Flask session, using the Flask-Session extension, we set it outside of the if __name__ == '__main__'
block.
For instance, we write
from flask import Flask, session
app = Flask(__name__)
app.secret_key = "super secret key"
# ...
if __name__ == "__main__":
app.debug = True
app.run()
to set the app.secret_key
property before we call app.run
in the if __name__ == "__main__"
block.
This is because flask run
skips the if __name__ == "__main__"
block.
We can run python app.py
to start the app if we want to run the if __name__ == "__main__"
block.
Conclusion
To fix secret key not set in Python Flask session, using the Flask-Session extension, we set it outside of the if __name__ == '__main__'
block.
Popular Posts
- Show / Hide div based on dropdown selected using jQuery
- Autosuggestion Select Box using HTML5 Datalist, PHP and MySQL with Example
- Custom Authentication Login And Registration Using Laravel 8
- Infinite Scrolling on PHP website using jQuery and Ajax with example
- Google Login or Sign In with Angular Application
- How to Convert MySQL Data to JSON using PHP
- How to change date format in PHP?
- Image Lazy loading Using Slick Slider
- Slick Slider Basic With Example
- php in_array check for multiple values
- Adaptive Height In Slick Slider
- Slick Slider Center Mode With Example
- How to Scroll to an Element with Vue 3 and ?
- JavaScript Multiple File Upload Progress Bar Using Ajax With PHP
- Slick Slider Multiple Items With Example