Django admin Error: ‘WSGIRequest’ object has no attribute ‘user’

Django admin error ‘wsgirequest’ object has no attribute ‘user’

Django version 1.8. Upgrade to django2.0

After the Django service is started, when logging into the admin background, the following error will be thrown:

Django admin error 'wsgirequest' object has no attribute 'user'

Google said that there is a problem with midview configuration, and the order should be kept. See( http://stackoverflow.com/questions/26576192/wsgirequest-object-has-no-attribute-user ):

'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',

But after this setting, it is still not solved.
My 1.8.3 midview configuration is as follows:

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

)

In fact, this is a problem with Django version. Before 1.10, the key of middleware was middware_ After midview, search is 1.10. So when the version of the development environment is inconsistent with other environments, you should be very careful, there will be holes.
Change the configuration to Django 2.0: (this is generated by Django 2.1 and directly copied and replaced)

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

Problem solving.

Similar Posts: