中间件函数的执行流程
Posted jec1999
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了中间件函数的执行流程相关的知识,希望对你有一定的参考价值。
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\',
\'mid.middleware.M1\',
\'mid.middleware.M2\',
\'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\',
\'mid.middleware.M1\',
\'mid.middleware.M2\',
]
1:一旦process_request返回,则不再执行下面中间件的process_request,直接执行该返回中间件的process_response,然后顺次往上执行.
2:process_request-->路由匹配-->process_view-->view函数-->process_response
3:一旦process_view返回的话,process_view不再往下执行,view函数也不执行,直接执行process_response
4.一旦view视图中报错了,就会走process_exception函数,若在process_exception一直未处理错误,则最终错误返回显示到浏览器,不友好
而一旦错误被处理(process_exception函数返回),则process_exception不再向上走,直接走process_response
以上是关于中间件函数的执行流程的主要内容,如果未能解决你的问题,请参考以下文章