Middleware
In Chapter 3, URL Mapping, Views, and Templates, we discussed Django’s implementation of the request/response process, along with its view and rendering functionality. In addition to these, another feature that plays an extremely important role when it comes to Django’s core web processing is middleware. Django’s middleware refers to a variety of software components that intervene in this request/response process to integrate important functionalities such as security, session management, and authentication.
So, when we write a view in Django, we don’t have to explicitly set a series of important security features in the response header. These additions to the response object are automatically made by the SecurityMiddleware
instance after the view returns its response. As middleware components wrap the view and perform a series of pre-processes on the request and post-processes on the response, the view is not cluttered with a lot of repetitive...