flash-session

1、session默认存放在浏览器的cookie中

源码

wsgi->app.__call__->wsgi_app->push->self.app.session_interface->session_interface = SecureCookieSessionInterface()->open_session和save_session

2、更改session储存的位置

a、下载

pip3 install -i https://pypi.douban.com/simple flask-session

b、源码分析

Session->self.init_app(app)->app.session_interface = self._get_interface(app)->session_interface

other

MemcachedSessionInterface
FileSystemSessionInterface
MongoDBSessionInterface
SqlAlchemySessionInterface

具体看源码

c、示例

import redis
from flask import Flask,session
# 1.导入模块
from flask_session import Session
# from flask.sessions import SecureCookieSession  # 原始
# from flask_session import RedisSessionInterface # 修改
app = Flask(__name__)

# app.session_interface = SecureCookieSessionInterface()
# app.session_interface = RedisSessionInterface()
# 2.修改配置文件
app.config[SESSION_TYPE] = redis
app.config[SESSION_REDIS] = redis.Redis(host=ip,port=6379,password=密码)
# 3.注册
Session(app)


@app.route(/login)
def login():
    session[user] = alex
    return Hello


@app.route(/home)
def index():
    print(session.get(user))

    return World


if __name__ == __main__:
    app.run()

相关文章

  译序:JWMediaPlayer是开源的网页使用的Flash播放器。本...
    Flash编程原理都是只能将1写为0,而不能将0写成1.所...
 上传setenvgatewayip192.168.1.1;setenvserverip192.168.1...
Error:FlashDownloadFailed-"Cortex-M3"出现一般有...
jPlayer是一个用于控制和播放mp3文件的jQuery插件。它在后台...
#ifndef__FONTUPD_H__#define__FONTUPD_H__#include"sy...