当前位置:网站首页>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
边栏推荐
- ftp常用命令详解_iftop命令详解
- Unit 4 Routing Layer
- window10下半自动标注
- yolov5改进(一) 添加注意力集中机制
- [ROS](06)ROS通信 —— 话题(Topic)通信
- How does Apache, the world's largest open source foundation, work?
- 【Tensorflow】AttributeError: module 'keras.backend' has no attribute 'tf'
- 深度学习框架pytorch快速开发与实战chapter3
- The future of financial services will never stop, and the bull market will continue 2021-05-28
- 浅浅写一下PPOCRLabel的使用及体验
猜你喜欢
随机推荐
浅浅写一下PPOCRLabel的使用及体验
[ROS] (06) ROS Communication - Topic Communication
paddleocr window10初体验
Flask项目的完整创建 七牛云与容联云
关于市场后市的发展预测? 2021-05-23
chapter6可视化(不想看版)
window10下半自动标注
The world's largest Apache open source foundation is how it works?
Flask框架深入一
Verilog学习 系列
paddle window10环境下使用conda安装
【Tensorflow】AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'
线代:已知一个特征向量快速求另外两个与之正交的特征向量
Supervision strikes again, what about the market outlook?2021-05-22
AWVS工具介绍[通俗易懂]
redis分布式锁和看门狗的实现
STM32(F407)—— 堆栈
使用云GPU+pycharm训练模型实现后台跑程序、自动保存训练结果、服务器自动关机
瑞吉外卖笔记——第08讲读写分离
Interview | with questions to learn, Apache DolphinScheduler Wang Fuzheng




创建&编译ROS软件包Package](/img/c2/5931d5cbade509c6ca34d66a274756.png)

CMakeLists.txt详解](/img/34/577c729f06748f625ca0c223496d48.png)

