2 回答
TA贡献1820条经验 获得超2个赞
设置为函数process_view(...)的属性 为middleware(...)
def process_view(request, view_func, view_args, view_kwargs):
"""
do something
"""
def simple_middleware(get_response):
# One-time configuration and initialization.
def middleware(request):
# Code to be executed for each request before
# the view (and later middleware) are called.
response = get_response(request)
# Code to be executed for each request/response after
# the view is called.
return response
middleware.process_view = process_view
return middleware
TA贡献1111条经验 获得超0个赞
* process_view()应该返回None
一个HttpResponse对象,否则会出现错误。
该函数具有process_view()
:
def process_view(request, view_func, view_args, view_kwargs):
# Do something
def simple_middleware(get_response):
# One-time configuration and initialization.
def middleware(request):
# Code to be executed for each request before
# the view (and later middleware) are called.
response = get_response(request)
# Code to be executed for each request/response after
# the view is called.
return response
middleware.process_view = process_view # Here
return middleware
班级有process_view():
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
def process_view(self, request, view_func, view_args, view_kwargs):
# Do something
添加回答
举报