We will be disscussing the points: 1. What is a middleware 2. When to use middleware 3. Things to remember when writing middleware 4. Writing some middlewares to understand how order of middleware matters What is a middleware Middlewares are hooks to modify Django request or response object. Putting the definition of middleware from Django docs . Middleware is a framework of hooks into Django ’ s request / response processing . It ’ s a light , low - level “ plugin ” system for globally altering Django ’ s input or output . When to use middleware You can use middleware if you want to modify the request i.e HttpRequest object which is sent to the view. Or you might want to modify the HttpResponse object returned from the view. Both these can be achieved by using a middleware. You might want to perform an operation before the view executes. In such case you would use a middle...
Hi, I’m Deepak Dubey. The founder of this blog. I’m a Full-stack Python Developer | OpenedX professional and part-time blogger. I’m here to write the blogs related to technology stuff like Python, Django , Open-edX, Data Science, machine Learning and many more.