Ricardo

Flask session 使用与源码笔记

阅读时长: 1 分钟

设置session

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from flask import Flask, session

app = Flask(__name__)
import os
app.secret_key = os.environ['FLASK_SECRET_KEY']
@app.route('/x1')
def index():
  session['k1'] = 123
  return "index"

@app.route('/x2')
def order():
	print(session['k1'])
  return "order"
Python
1
obj['xxxx'] = 123  # __setitem__方法

流程分析

image-20201206231459996

源码解读

session源码1

源码解读二,分析类

session源码2类封装

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
记录自己
Built with Hugo
主题 Stack 由 Jimmy 设计