@setupmethod
def teardown_appcontext(self, f):
"""Registers a function to be called when the application context
ends. These functions are typically also called when the request
context is popped.
Example::
ctx = app.app_context()
ctx.push()
...
ctx.pop()
When ``ctx.pop()`` is executed in the above example, the teardown
functions are called just before the app context moves from the
stack of active contexts. This becomes relevant if you are using
such constructs in tests.
Since a request context typically also manages an application
context it would also be called when you pop a request context.
When a teardown function was called because of an exception it will
be passed an error object.
.. versionadded:: 0.9
"""
self.teardown_appcontext_funcs.append(f)
def teardown_appcontext(self, f):
"""Registers a function to be called when the application context
ends. These functions are typically also called when the request
context is popped.
Example::
ctx = app.app_context()
ctx.push()
...
ctx.pop()
When ``ctx.pop()`` is executed in the above example, the teardown
functions are called just before the app context moves from the
stack of active contexts. This becomes relevant if you are using
such constructs in tests.
Since a request context typically also manages an application
context it would also be called when you pop a request context.
When a teardown function was called because of an exception it will
be passed an error object.
.. versionadded:: 0.9
"""
self.teardown_appcontext_funcs.append(f)
return f
谷歌翻译结果:
“”注册函数时被调用的应用程序上下文
结束。这些功能通常也被称为请求时
弹出上下文。
例如::
CTX= app.app_context()
(ctx.push)
...
(ctx.pop)
当`` ctx.pop()``在上面的例子中,执行拆机
函数被调用之前从移动应用程序上下文
堆叠活性上下文。如果您正在使用,这将成为相关
这样的结构测试。
因为请求上下文通常还管理一个应用程序
情况下,它也被称为当你弹出一个请求上下文。
因为异常会被称为当拆卸功能
传递一个错误对象。
.. versionadded::0.9
“”“
大概意思应该是你把一个东西加入到context,那么工作完成后你就要把它释放掉。