中間件函數的執行流程
阿新 • • 發佈:2017-10-09
messages exception 流程 log ssi cati src image esp
‘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,然後順次往上執行.
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‘, ] 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
中間件函數的執行流程