Usage#
│ │ │Quickstart#
│ │ │ -Create your Flask
application, load the configuration of choice, and
│ │ │ +
Create your Flask
application, load the configuration of choice, and
│ │ │ then create the Session
object by passing it the application.
from flask import Flask, session
│ │ │ from flask_session import Session
│ │ │
│ │ │ app = Flask(__name__)
│ │ │
│ │ │ SESSION_TYPE = 'redis'
│ │ │ @@ -261,27 +261,27 @@
│ │ │ return session.get('key', 'not set')
│ │ │
See the configuration section for more details.
│ │ │Note
│ │ │You can not use Session
instance directly, what Session
does
│ │ │ -is just change the session_interface
attribute on
│ │ │ -your Flask applications. You should always use flask.session
when accessing or modifying the current session.
session_interface
attribute on
│ │ │ +your Flask applications. You should always use flask.session
when accessing or modifying the current session.
│ │ │ Alternative initialization#
│ │ │Rather than calling Session
, you may initialize later using init_app()
.
...
│ │ │ sess = Session()
│ │ │ sess.init_app(app)
│ │ │
Or, if you prefer to directly set parameters rather than using the configuration constants, you can initialize by setting an instance of flask_session.redis.RedisSessionInterface
directly to the flask.Flask.session_interface
.
Or, if you prefer to directly set parameters rather than using the configuration constants, you can initialize by setting an instance of flask_session.redis.RedisSessionInterface
directly to the flask.Flask.session_interface
.
from flask import Flask, session
│ │ │ from flask_session.redis import RedisSessionInterface
│ │ │ from redis import Redis
│ │ │
│ │ │ app = Flask(__name__)
│ │ │
│ │ │ redis = Redis(host='localhost', port=6379)
│ │ │ ├── html2text {}
│ │ │ │ @@ -41,15 +41,15 @@
│ │ │ │ * _C_h_a_n_g_e_s
│ │ │ │ _B_a_c_k_ _t_o_ _t_o_p
│ │ │ │ _E_d_i_t_ _t_h_i_s_ _p_a_g_e
│ │ │ │ Toggle Light / Dark / Auto color theme
│ │ │ │ Toggle table of contents sidebar
│ │ │ │ ************ UUssaaggee_## ************
│ │ │ │ ********** QQuuiicckkssttaarrtt_## **********
│ │ │ │ -Create your _F_l_a_s_k application, load the configuration of choice, and then
│ │ │ │ +Create your Flask application, load the configuration of choice, and then
│ │ │ │ create the Session object by passing it the application.
│ │ │ │ from flask import Flask, session
│ │ │ │ from flask_session import Session
│ │ │ │
│ │ │ │ app = Flask(__name__)
│ │ │ │
│ │ │ │ SESSION_TYPE = 'redis'
│ │ │ │ @@ -64,25 +64,25 @@
│ │ │ │
│ │ │ │ @app.route('/get/')
│ │ │ │ def get():
│ │ │ │ return session.get('key', 'not set')
│ │ │ │ See the configuration section for more details.
│ │ │ │ Note
│ │ │ │ You can not use Session instance directly, what Session does is just change the
│ │ │ │ -_s_e_s_s_i_o_n___i_n_t_e_r_f_a_c_e attribute on your Flask applications. You should always use
│ │ │ │ -_f_l_a_s_k_._s_e_s_s_i_o_n when accessing or modifying the current session.
│ │ │ │ +session_interface attribute on your Flask applications. You should always use
│ │ │ │ +flask.session when accessing or modifying the current session.
│ │ │ │ ********** AAlltteerrnnaattiivvee iinniittiiaalliizzaattiioonn_## **********
│ │ │ │ Rather than calling Session, you may initialize later using init_app().
│ │ │ │ ...
│ │ │ │ sess = Session()
│ │ │ │ sess.init_app(app)
│ │ │ │ Or, if you prefer to directly set parameters rather than using the
│ │ │ │ configuration constants, you can initialize by setting an instance of
│ │ │ │ flask_session.redis.RedisSessionInterface directly to the
│ │ │ │ -_f_l_a_s_k_._F_l_a_s_k_._s_e_s_s_i_o_n___i_n_t_e_r_f_a_c_e.
│ │ │ │ +flask.Flask.session_interface.
│ │ │ │ from flask import Flask, session
│ │ │ │ from flask_session.redis import RedisSessionInterface
│ │ │ │ from redis import Redis
│ │ │ │
│ │ │ │ app = Flask(__name__)
│ │ │ │
│ │ │ │ redis = Redis(host='localhost', port=6379)