我正在阅读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()