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:
- Django @csrf_exempt Cannot work in class view (Django @csrf_exempt not working in class View)
- [Django CSRF tutorial] solve the problem of forbidden (403) CSRF verification failed. Request aborted
- ERRORS: ?: (corsheaders.E013) Origin ‘*’ in CORS_ORIGIN_WHITELIST is missing scheme or ne…
- [Solved] DjangoORM Run python manage.py makemigrations Error: no changes detected
- “No module named context_processors”
- Error encountered in Django: forbidden CSRF cookie not set
- How to Solve Django xadmin installation Error [7 Types of Errors]
- Vue + Django Project-Browser cross-domain error: Access-Control-Allow-Origin
- Python2.7 Error: command not found: django-admin.py [How to Solve]
- ImportError: cannot import name ‘patterns’