

middleware<--全靠它!
Initializer: init(self)
出于性能的考慮,每個(gè)已啟用的中間件在每個(gè)服務(wù)器進(jìn)程中只初始化一次(服務(wù)進(jìn)程啟動(dòng)的時(shí)候調(diào)用)。
對(duì)自身的檢查
過(guò)。
process_request(self, request)
request預(yù)處理函數(shù)
在Django接收到request之后,但仍未解析URL以確定應(yīng)當(dāng)運(yùn)行的view之前。調(diào)用
返回 None(Django將繼續(xù)處理這個(gè)request,執(zhí)行后續(xù)的中間件, 然后調(diào)用相應(yīng)的view,“我對(duì)繼續(xù)處理這個(gè)request沒(méi)意見(jiàn)”)
或者返回 HttpResponse 對(duì)象(Django 將不再執(zhí)行任何其它的中間件(無(wú)視其種類)以及相應(yīng)的view。 Django將立即返回該 HttpResponse,“我不想其他代碼處理這個(gè)request,我要提早返回” ).
process_view(self, request, callback, callback_args, callback_kwargs)
view預(yù)處理函數(shù)
在Django執(zhí)行完request預(yù)處理函數(shù)并確定待執(zhí)行的view之后,但在view函數(shù)實(shí)際執(zhí)行之前。
process_response(self, request, response)
Response后處理函數(shù)
在****Django****執(zhí)行view****函數(shù)****并生成****response****之后
該處理器能修改response****的內(nèi)容
django-HttpRequest
HttpRequest.POST
A dictionary-like object containing all given HTTP POST parameters, providing that the request contains form data. See the QueryDict
documentation below. If you need to access raw or non-form data posted in the request, access this through the HttpRequest.body
attribute instead.
It’s possible that a request can come in via POST with an empty POST dictionary – if, say, a form is requested via the POST HTTP method but does not include form data. Therefore, you shouldn’t use ifrequest.POST to check for use of the POST method; instead, use if request.method == "POST" (see above).
Note: POST does not include file-upload information. See FILES
.
類似字典的object,返回所有http post請(qǐng)求的參數(shù),formed data,如果想看原始數(shù)據(jù),HttpRequest.body
可能為空,需要檢測(cè)