Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the middleware of Django?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the middleware of Django". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the middleware of Django?"

What is middleware (middleware)

Middleware (middleware) in django, in django, middleware is actually a class. After the request arrives and ends, django will execute the corresponding methods in the middleware at the right time according to its own rules.

In the settings module of the django project, there is a MIDDLEWARE_CLASSES variable, and each element is a middleware

Custom middleware:

1. One or more methods that can be defined in middleware:

Process_request (self,request) send request

Process_view (self,request, view_func, view_args, view_kwargs) views function processing

Process_template_response (self,request, response)

Process_exception (self,request, exception) exception handling is performed only when views reports an error

Process_response (self,request, response) returns the result

2. Create a middleware class a, create a new XXX package or folder b, create a new AAA.py module c, write as the following class in AAA.py, the class contains one or more of the following functions, function name and parameters cannot be changed d, import middleware module, from django.utils.deprecation import MiddlewareMixin

MIDDLEWARE = [

'common.middleware.auth.AuthMiddleware'

]

At this point, I believe you have a deeper understanding of "what is the middleware of Django". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report