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.
- Create file called middleware.py in your app folder.
- Define inside middleware.py your middleware class/function.
- Set settings.py to use your middleware by append to MIDDLEWARE :