I am looking into django middleware codebase. I looked into following diagram
So, the diagram is quite clear.
But I have some questions
What happens when exception comes in process_request() middleware ? How is it handled ? Will the response_middleware be invoked ? Eg. if exception comes in
process_view()
ofAuthenticationMiddleware
, then willprocess_response()
ofMessageMiddleware
be invoked ?What happens when in process_response() middleware returns response? Eg. if
process_view()
ofAuthenticationMiddleware
returns respones, then willprocess_response()
ofMessageMiddleware
be invoked ? OR it'll turn back fromAuthenticationMiddleware
(ie, it'll invokeprocess_response()
ofAuthenticationMiddleware
, but will not invokeprocess_response()
ofMessageMiddleware
)
I have debugged the behaviour of django in 1.10 where new style middleware classes are used, but I am not familiar about old MIDDLEWARE_CLASSES
settings ?
For django 1.10:-
1) If process_request()
for AuthenticationMiddleware
returns response, then process_template_response()
and process_response()
will be invoked as show in the figure given below for all the middlewares.
2) If process_request()
for AuthenticationMiddleware
raises exception, then also the behavior will be the same.
Correct me, If I am wrong.
Thanks in Advance.