标签:组件 idt messages rom 倒序 src ssi uri set
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‘, ]
from django.utils.deprecation import MiddlewareMixin class CsrfViewMiddleware(MiddlewareMixin): def process_request(self, request): csrf_token = self._get_token(request) if csrf_token is not None: # Use same token next time. request.META[‘CSRF_COOKIE‘] = csrf_token
settings 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‘, ‘app01.middleC.Login‘ ]
1.执行时间:在视图函数views执行之前 2.参数:request -->跟视图函数一致,都是一个对象,可以对其封装属性 3.执行顺序:多个中间件时,按照注册顺序执行, 4.返回值: None:正常流程,依次往下走; return response对象,会直接从这结束,视图函数也不会执行,开始返回给浏览器一个response对象;
当前中间件之后的中间件的request方法都不执行;所以也没有response方法;
执行时间:在views函数之后调用,
参数:(request,response)
返回值:这里因为是在views函数之后调用,所以要接收一个response对象要返回;
执行顺序:对个中间件时,按注册顺序倒序执行,
标签:组件 idt messages rom 倒序 src ssi uri set
原文地址:https://www.cnblogs.com/0627zhou/p/9792728.html