flask-session

flask-session

通过这种方式可以把session存入redis。

from flask import Flask,session
from redis import Redis
from flask_session import Session
app = Flask(__name__)
app.config['SESSION_TYPE'] = 'redis'
app.config['SESSION_REDIS'] = Redis(host='127.0.0.1',port='6379')
Session(app)

@app.route('/')
def hello_world():
    session['name']='jason'
    return 'Hello World!'

@app.route("/index")
def index():
    print(session['name'])
    return "ok"

if __name__ == '__main__':
    app.run()
posted @ 2020-01-05 18:13  chanyuli  阅读(94)  评论(0编辑  收藏  举报