To activate a middleware component, add it to the MIDDLEWARE_CLASSES
list in your Django settings.
In MIDDLEWARE_CLASSES
, each middleware component is represented by a string: the full Python path to the middleware's class name. For example, here's the default value created by django-admin startproject
:
MIDDLEWARE_CLASSES = [ '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', ]
A Django installation doesn't require any middleware-MIDDLEWARE_CLASSES
can be empty, if you'd like-but it's strongly suggested that you at least use CommonMiddleware
.
The order in MIDDLEWARE_CLASSES
matters because a middleware can depend on other middleware. For...