当前位置:网站首页>Unit 8 Middleware
Unit 8 Middleware
2022-08-02 14:20:00 【czy1206527605】
One. Middleware
What is it
Middleware in Django is a lightweight, low-level plug-in system that can intervene in Django's request and response processing and globally modify Django's input or output.
What to do
If you want to modify the request, such as the HttpRequest object passed to the view.Or you want to modify the HttpResponse object returned by the view, which can be achieved through middleware.
Where:
MIDDLEWARE = ['django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',]2. Principle and application of middleware
The principle of middleware
Common hook methods
process_request(self,request) # This method will be executed before django processes the requestprocess_response(self, request, response) # After django returns the response, execute this methodDefine and call
Create define middleware location
Custom Middleware
The first def
calls this middleware before processing the request
The second def
returns the middleware after the view returns the response
3. Registration and use of middleware
Registration of middleware
Middleware effect
Normal effect

Incorrect effect
边栏推荐
猜你喜欢

瑞吉外卖笔记——第05讲Redis入门
![[ROS] The difference between roscd and cd](/img/a8/a1347568170821e8f186091b93e52a.png)
[ROS] The difference between roscd and cd

如何选择正规的期货交易平台开户?

Unit 15 Paging, Filtering

The 2nd China Rust Developers Conference (RustChinaConf 2021~2022) Online Conference Officially Opens Registration

Interview | with questions to learn, Apache DolphinScheduler Wang Fuzheng

第十一单元 序列化器

Deep learning framework pytorch rapid development and actual combat chapter3

如何解决mysql服务无法启动1069

The most complete ever!A collection of 47 common terms of "digital transformation", read it in seconds~
随机推荐
[ROS] The difference between roscd and cd
What are the file encryption software?Keep your files safe
第十四单元 视图集及路由
[ROS]ROS常用工具介绍(待续)
Go语言初始
Cloin 控制台乱码
Flask框架
Unit 4 Routing Layer
文件加密软件有哪些?保障你的文件安全
[ROS]roscd和cd的区别
Unit 10 Continuous Tuning
paddleocr window10 first experience
rpm包的卸载与安装[通俗易懂]
Sentinel源码(六)ParamFlowSlot热点参数限流
paddleocr window10初体验
What is the difference between web testing and app testing?
You can't accept 60% slump, there is no eligible for gain of 6000% in 2021-05-27
The future of financial services will never stop, and the bull market will continue 2021-05-28
Flask-RESTful请求响应与SQLAlchemy基础
redis延时队列