Summary of Django middleware and summary of Django Middleware

Source: Internet
Author: User

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

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.