当前位置:网站首页>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
边栏推荐
- 跑跑yolov5吧
- MobileNet ShuffleNet & yolov5 replace backbone
- Flask框架
- shell脚本“画画”
- MySQL数据库设计规范
- Flask上下文,蓝图和Flask-RESTful
- Supervision strikes again, what about the market outlook?2021-05-22
- Unit 11 Serializers
- 深度学习框架pytorch快速开发与实战chapter3
- The future of financial services will never stop, and the bull market will continue 2021-05-28
猜你喜欢
随机推荐
The most complete ever!A collection of 47 common terms of "digital transformation", read it in seconds~
【Tensorflow】AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'
Audio processing: floating point data stream to PCM file
paddleocr window10初体验
The future of financial services will never stop, and the bull market will continue 2021-05-28
浅浅写一下PPOCRLabel的使用及体验
专访|带着问题去学习,Apache DolphinScheduler 王福政
Raft对比ZAB协议
第七单元 ORM表关系及操作
【ROS】编译软件包packages遇到进度缓慢或卡死,使用swap
VMM是什么?_兮是什么意思
【Tensorflow】AttributeError: module 'keras.backend' has no attribute 'tf'
第四单元 路由层
【ROS】工控机的软件包不编译
drf源码分析与全局捕获异常
第十二单元 关联序列化处理
如何解决mysql服务无法启动1069
Sentinel源码(二)入口方法分析
Flask项目的完整创建 七牛云与容联云
redis延时队列







![[ROS] The software package of the industrial computer does not compile](/img/a8/a1347568170821e8f186091b93e52a.png)

