当前位置:网站首页>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 method
Define 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
边栏推荐
猜你喜欢
[ROS] (01) Create ROS workspace
[ROS] The difference between roscd and cd
window10下半自动标注
MobileNet ShuffleNet & yolov5 replace backbone
跑yolov5又出啥问题了(1)p,r,map全部为0
Flask框架的搭建及入门
yolov5,yolov4,yolov3 mess
The most complete ever!A collection of 47 common terms of "digital transformation", read it in seconds~
第五单元 保持状态
logback源码阅读(一)获取ILoggerFactory、Logger
随机推荐
【Tensorflow】AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'
理解TCP长连接(Keepalive)
chapter6可视化(不想看版)
无序数组排序并得到最大间隔
网页设计(新手入门)[通俗易懂]
动手学ocr(一)
[ROS] (06) ROS Communication - Topic Communication
Swagger 的使用
paddleocr window10初体验
Sentinel源码(五)FlowSlot以及限流控制器源码分析
mysql的case when如何用
Tornado框架路由系统介绍及(IOloop.current().start())启动源码分析
关于密码加密的一点思路
MySQL数据库设计规范
You can't accept 60% slump, there is no eligible for gain of 6000% in 2021-05-27
第六单元 初识ORM
[ROS] Compiling packages packages encounters slow progress or stuck, use swap
drf视图组件
8576 顺序线性表的基本操作
瑞吉外卖笔记——第05讲Redis入门