Move the project to a higher version of django, suggesting 408,409,410 middleware wrong solution

将项目迁移至django2.X, 中间件提示错误为:

ERRORS:
?: (admin.E408) 'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MIDDLEWARE in order to use the admin application.
?: (admin.E409) 'django.contrib.messages.middleware.MessageMiddleware' must be in MIDDLEWARE in order to use the admin application.
?: (admin.E410) 'django.contrib.sessions.middleware.SessionMiddleware' must be in MIDDLEWARE in order to use the admin application.

 

Solution:

Writing format and modify variable names middleware can be.

Note: variable name from MIDDLEWARE_CLASSES become MIDDLEWARE

Settings in previous projects django middleware default format is written:

Copy the code
MIDDLEWARE_CLASSES = (
    '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', 'django.middleware.security.SecurityMiddleware', )
Copy the code


The use of the new version of Django to create a new project, middleware written format as ↓↓↓:

Copy the code
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', ]
Copy the code


We can see the new version of django modify the middleware written format: the transition from the tuple list and removed a middleware, SessionAuthenticationMiddleware.


Writing format and modify variable names middleware can solve this problem.

 

As SessionAuthenticationMiddleware middleware, if there have been, you can comment out

Otherwise error:

AttributeError: module 'django.contrib.auth.middleware' has no attribute 'SessionAuthenticationMiddleware'

The above exception was the direct cause of the following exception:

...

...

...

django.core.exceptions.ImproperlyConfigured: WSGI application 'yourproject.wsgi.application' could not be loaded; Error importing module.

Guess you like

Origin www.cnblogs.com/hongdoudou/p/12637509.html