What is Django Middleware

Middlewares are hooks to modify Django request or response object. Or In Django, middleware is a plugin that processes during request and response execution. Middleware is used to perform a function in the application. The functions can be a security, session, csrf protection, authentication etc. We can use middleware if we want to modify the request i.e HttpRequest object Or want to modify the HttpResponse object. Django provides various built-in middleware and also allows us to write our own middleware. settings.py file of Django project contains various middleware.
List of middleware in settings.py

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',  
] 

 

Total Views: 482