Instagram
youtube
Facebook
Twitter

Django Middleware

Django Middlewares

In Django, a middleware is a regular python class used to perform any function in our web application. These classes hold pieces of code that are processed upon every response our Django application gets. These middlewares can handle tasks related to sessions, security, CSRF protection, Authentication, messages, etc. 

There are mainly two types of middleware:

  • Function-Based Middleware.
  • Class-Based MIddleware.

Django also provides various inbuilt middleware. They are saved in the settings.py MIDDLEWARE section. You can also write your own middleware according to your requirements.

After, creating your own middleware you can activate the middleware by adding it to your settings.py middleware section.