I'm implementing a new middleware using a standard implementation:
def my_middleware(get_response):
def middleware(request):
return get_response(request)
return middleware
I want to get the view_args
. I can change to a class-based middleware and implement the method
process_view(request, view_func, view_args, view_kwargs)
Is there any other way to get these view_args, view_kwargs in my middleware without changing to class-based middleware?
set process_view(...)
as an attribute of middleware(...)
function as
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