后台登录不了并提示'WSGIRequest' object has no attribute 'user'

来自linux中国网wiki
Evan讨论 | 贡献2019年10月14日 (一) 13:55的版本 (导入1个版本)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索
WARNINGS:
?: (1_7.W001) MIDDLEWARE_CLASSES is not set.
        HINT: Django 1.7 changed the global defaults for the MIDDLEWARE_CLASSES. django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware, and django.contrib.messages.middleware.MessageMiddleware were removed from the defaults. If your project needs these middleware then you should configure this setting.

My solution

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

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


其实就改了个列表名而已 
MIDDLEWARE  --> MIDDLEWARE_CLASSES
 ,我开始还搞错了 搞成了 元组
原因 是 以前的都是元组,而现在 完善了,都是列表  这个昨天说错了 我今天在cenots7 + django1.8  得出的也是元组呢,应该是我本地的kali出问题了  20170916am

还有就是以前 都是 MIDDLEWARE_CLASSES 为什么 今天变成了 MIDDLEWARE 呢

See Also

External links

'WSGIRequest' object has no attribute 'user'

'WSGIRequest' object has no attribute 'user' Django admin