Summary of Django middleware and summary of Django Middleware
I. Middleware
-- Middleware is a lightweight, underlying plug-in system that can be added to Django's request and response processes to modify Django's input and output.
-- Each middleware component is an independent Python class that can define one or more of the following methods
-- _ Init __: No parameter is required. The server calls the first request to determine whether to enable the current middleware.
-- Process_request (request): called before the execution view, and called on each request, the returned None or HttpResponse object
-- Process_view (request, view_func, view_args, view_kwargs): called before calling the view function, called on each request, and returned None or HtppResponse object
-- Process_template_response (request, response)
-- Process_response (request, response): all responses are called before the browser is returned. Each request is called and the HttpResponse object is returned.
-- Process_exception (request, response, exception): When a view throws an exception, it is called on each request and an HttpResponse object is returned.
A. What is middleware?
-- Middleware is a class
B. What are precautions for returned values?
-- No return value: continue to execute subsequent function middleware and view functions.
-- Return Value: Execute process_response with the returned value and the above response.
C. What has middleware done:
-- User Logon
-- Logging
-- Permission management
-- Session
-- Csrf
Process_view
D. Differences between middleware and decorator
-- Middleware is used for batch operations, and the decorator is used for a single