我们留意到,0.9版本的“请求高低文”的pop办法中,当要将一个“请求高低文”推入_request_ctx_stack栈中的时刻,会先检查另一个栈_app_ctx_stack的┞坊顶是否存在“应用高低文”对象或者栈顶的“应用高低文”对象的应用是否是当前应用。如不雅不存在或者不是当前对象,Flask会主动师长教师成一个“应用高低文”对象,并将其推入_app_ctx_stack中。
我们再看分开高低文时的相干代码:
- # Flask v0.9
- def pop(self, exc=None):
- """Pops the request context and unbinds it by doing that. This will
- also trigger the execution of functions registered by the
- :meth:`~flask.Flask.teardown_request` decorator.
- .. versionchanged:: 0.9
- Added the `exc` argument.
- """
- app_ctx = self._implicit_app_ctx_stack.pop()
- clear_request = False
- if not self._implicit_app_ctx_stack:
- self.preserved = False
- if exc is None:
- exc = sys.exc_info()[1]
- self.app.do_teardown_request(exc)
- clear_request = True
- rv = _request_ctx_stack.pop()
- assert rv is self, 'Popped wrong request context. (%r instead of %r)'
- % (rv, self)
推荐阅读
2025年全球数据将攀升至163ZB,10倍的数据增长来源于哪?
【51CTO.com原创稿件】比来,希捷科技与IDC合营宣布了一份名为《数据时代2025》的数据成长趋势申报,这份白皮>>>详细阅读
本文标题:Flask中的请求上下文和应用上下文
地址:http://www.17bianji.com/lsqh/35165.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示