【发布时间】:2016-02-02 12:38:53
【问题描述】:
我正在阅读 github 中 Werkzeug 库的源代码,并且在其中一个示例(命名为 Simplewiki)中,application.py 文件中有一个函数将应用程序绑定到当前活动上下文.我想知道为什么这是必要的,或者我在哪里可以找到解释这一点的东西?
函数是这样的:
def bind_to_context(self):
"""
Useful for the shell. Binds the application to the current active
context. It's automatically called by the shell command.
"""
local.application = self
这就是调度程序绑定请求的部分。
def dispatch_request(self, environ, start_response):
"""Dispatch an incoming request."""
# set up all the stuff we want to have for this request. That is
# creating a request object, propagating the application to the
# current context and instanciating the database session.
self.bind_to_context()
request = Request(environ)
request.bind_to_context()
【问题讨论】:
标签: python python-2.7 werkzeug