m1.py
from django.middleware.csrf import CsrfViewMiddleware
from django.utils.deprecation import MiddlewareMixin
class Middle1(MiddlewareMixin):
def process_request(self,request):
print('m1.process_request')
def process_response(self,request,response):
print('m1.process_response')
return response
def process_view(self, request, callback, callback_args, callback_kwargs):
print('m1.process_view')
# print('callback',callback)
# print('callbackargs',callback_args)
return callback(request,*callback_args,**callback_kwargs)
class Middle2(MiddlewareMixin):
def process_request(self,request):
print('m2.process_request')
def process_response(self,request,response):
print('m2.process_response')
return response
def process_view(self, request, callback, callback_args, callback_kwargs):
print('m2.process_view')
settings.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'm1.Middle1',
'm1.Middle2'
]