flask的session
from flask import Flask, session, request
app = Flask(__name__)
# 要用session,必须在APP中配置一个秘钥
app.secret_key = 'ajkjalkjakj'
app.config['SESSION_COOKIE_NAME'] = 'Alenhandsome'
# app.session_interface
# app.session_interface实现了两个方法,一个叫save_session,一个叫open_session
@app.route('/')
def index():
# 如何设置session
# 1、先导入session
# 2、给session设置值
session['name'] = 'tank'
session['name1'] = 'owen'
return 'ok'
@app.route('/login')
def login():
print(session['name'])
return 'login'
if __name__ == '__main__':
app.run()
分析session的原理