Flask找上下文源码

1. app = Flask(name)

app.call

1.1 按住 command 键 点击 进到这个函数里

1.2 接着找 return 看看返回什么 点进去

1.3 找到定义函数

1.4 点进去先看这个里边有啥

1.5 找到定义类

1.6 找到RequestContext 类

1.7 找到 RequestContext ---> 的push 方法

1.8 点击 _cv_request 找到 globals.py 下的 _cv_request栈

2. 在wsgi的push方法中

2.1 进到push 方法

2.2 进到 app_context

2.3 进到APPContext

2.4 在ctx.py下 找到AppContext 类

2.5 找到AppContext --> 的push 方法

2.6 点击 _cv_app ---> 找到 globals.py 下的 _cv_app栈

3. 找到 --> APPContext --> RequestContext

3.1 进到LocalProxy

栈入口

栈的入口可以理解为:

应用上下文入口:当 app_ctx.push() 被调用时,应用上下文被推入栈。

请求上下文入口:当 _cv_request.set(self) 被调用时,当前请求上下文被推入栈。

栈退出

栈的退出通常在 pop() 方法中处理。Flask 在每个请求完成时,会自动调用请求上下文和应用上下文的弹出逻辑。

相关推荐
YJlio4 小时前
1.7 通过 Sysinternals Live 在线运行工具:不下载也能用的“云端工具箱”
c语言·网络·python·数码相机·ios·django·iphone
l1t4 小时前
在wsl的python 3.14.3容器中使用databend包
开发语言·数据库·python·databend
青云计划5 小时前
知光项目知文发布模块
java·后端·spring·mybatis
Victor3565 小时前
MongoDB(9)什么是MongoDB的副本集(Replica Set)?
后端
Victor3565 小时前
MongoDB(8)什么是聚合(Aggregation)?
后端
山塘小鱼儿5 小时前
本地Ollama+Agent+LangGraph+LangSmith运行
python·langchain·ollama·langgraph·langsimth
码说AI6 小时前
python快速绘制走势图对比曲线
开发语言·python
wait_luky6 小时前
python作业3
开发语言·python
yeyeye1116 小时前
Spring Cloud Data Flow 简介
后端·spring·spring cloud