源码剖析.Python.深入源码剖析Flask程序请求上下文?
上下文的分类 1.Flask上下文分为application context和request context,即应用上下文和请求上下文,这两者都处于同一请求的局部中 上下文类的定义 /usr/lib/Python27/lib/site-packages/flask/ctx.py class AppContext(object): def __init__(self, app): self.app = app self.url_adapter = app.create_url_adapter(None) self.g = app.app_ctx_globals_class() # Like request context, app contexts can be pushed multiple times # but there a basic "refcount" is enough to track them. self._refcnt = 0 说明:AppContext类即为程序上下文,内部保存几个变量,app为当前程序实例,g用来保存每个请求中需要用到的请求内全局变量 /usr/lib/Python27/lib/site-packages/flask/ctx.py class RequestContext(object): def __init__(self, app,