django middleware usage

  Middleware is django request / response processing hooks frame. This is a lightweight lower 'plug' system for globally changing the input or the output django

  Each middleware are responsible for completing some specific features.

  The following highlights some of the role of middleware

  1. Activate:

  To activate middleware, you need to add it to MIDDLEWARE_CLASSES inside, which is a global django settings.py in the configuration file. Each middleware component represented by a string: the full Python path to the middleware's class name, for example: The following is a list of middleware to create a django project is automatically created:

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware' ,
    'django.contrib.sessions.middleware.SessionMiddleware' ,
    'django.middleware.common.CommonMiddleware' , 
    'django.middleware.csrf.CsrfViewMiddleware' ,
    ''django.contrib。 auth.middleware.AuthenticationMiddleware' ,
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware' ,
    'django.contrib.messages.middleware.MessageMiddleware' ,
    'django.middleware.clickjacking.XFrameOptionsMiddleware' ,
]

Guess you like

Origin www.cnblogs.com/supcwi/p/11114547.html