2017-02-23 266 views
1

因此Im爲Django的用戶帳戶 即時得到的錯誤消息「WSGIRequest」對象沒有屬性「用戶」的文檔以下文件要求把這個代碼Django的用戶帳戶的WSGIRequest'對象沒有屬性「用戶」

MIDDLEWARE_CLASSES = [ 
... 
"account.middleware.LocaleMiddleware", 
"account.middleware.TimezoneMiddleware", 
... 
    ] 

MIDDLEWARE_CLASSES已過時,所以我把兩行代碼,在短短的中間件。

INSTALLED_APPS = [ 
'account', 
'django.contrib.admin', 
'django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.messages', 
'django.contrib.sites', 
'django.contrib.staticfiles', 
] 

MIDDLEWARE = [ 
"account.middleware.LocaleMiddleware", 
"account.middleware.TimezoneMiddleware", 
'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', 
] 

根urls.py

from django.conf.urls import url, include 
    from django.contrib import admin 

    urlpatterns = [ 
    url(r'^admin/', admin.site.urls), 
    url(r"^account/", include("account.urls")), 
    ] 

我跑makemigrations賬戶,和我跑遷移。服務器用盡只是沒有錯誤罰款,但每當我去本地主機:8000 /帳號/登錄我要麼得到一個或沒有屬性「用戶」

+0

什麼Django的版本是您使用?另外,可能使用django 1.10.5重複http://stackoverflow.com/questions/37949198/wsgirequest-object-has-no-attribute-user-django-admin – helb

+0

,我查看了其他問題,但沒有答案實際上幫助 – jalen201

+0

感謝那個鏈接是我需要的 – jalen201

回答

0

我對這個解決方案,同時使用Django 2.0是爲了確保Django的中間件在django-user-accounts中間件之前出現,我認爲所有應用都是這樣。

簡單地改變周圍這個順序爲我工作:

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', 
    "account.middleware.LocaleMiddleware", 
    "account.middleware.TimezoneMiddleware", 
] 
相關問題