使用
from flask import session, Flask from flask_session import Session from redis import Redis app = Flask(__name__) app.config["SESSION_TYPE"] = "redis" #指定数据库 app.config["SESSION_REDIS"] = Redis("127.0.0.1",6379,db=15) #db 指定存在redis的那个分区 Session(app) @app.route("/login") def login(): session["key"] = "value" return "已经创建了session" @app.route("/look") def look(): return session.get("key") if __name__ == '__main__': app.run()
详细介绍
.....................