Implementing session handling with Flask-Session
The Flask-Session module, like Flask’s built-in session, is easy to configure and use, except the module extension does not store session data in the web browser.
Before you can configure this module, you must install it using the pip
command:
pip install flask-session
Then, import the Session
class into the main.py
module to instantiate and integrate the extension module into the Flask platform. The following main.py
snippet shows the configuration of Flask-Session:
from flask_session import Session app = Flask(__name__) app.config.from_file('config-dev.toml', toml.load) sess = Session() sess.init_app(app)
The Session
instance is only used for configuration and not for session handling per se. Flask’s session
proxy object should always directly access the session data for storage and retrieval.
Afterward, set some Flask-Session configuration variables, such as SESSION_FILE_THRESHOLD
, which sets...