【发布时间】:2020-05-21 16:21:27
【问题描述】:
正如标题所说,我想从这里使用“decorator_from_middleware”函数:https://docs.djangoproject.com/en/2.1/_modules/django/utils/decorators/
但是我只是对如何正确使用它感到困惑。我有我的自定义中间件类和所有正常的中间件设置。在装饰器的帮助下,我将如何合并此功能以便能够将我的中间件用作每个视图的基础?
示例: 假设我有一些中间件类
class SimpleMiddleware:
def __init__(self, get_response):
self.get_response = get_response
# One-time configuration and initialization.
def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.
response = self.get_response(request)
# Code to be executed for each request/response after
# the view is called.
return response
如何使用decorator_from_middleware(middleware_class): 并将其应用于特定视图?
【问题讨论】:
标签: python django decorator middleware