2

So im following the documentation for django-user-accounts Im getting an error message 'WSGIRequest' object has no attribute 'user' The documentation asked to put in this code

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

MIDDLEWARE_CLASSES is deprecated, so i put the two lines of code in just MIDDLEWARE.

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

root 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")),
   ]

I ran makemigrations for accounts , and i ran migrate. The server ran just fine with no errors , but whenever i go to localhost:8000/accounts/login i either get a 404 or no attribute 'user'

jalen201
  • 193
  • 14
  • What Django version are you using? Also, possible duplicate of http://stackoverflow.com/questions/37949198/wsgirequest-object-has-no-attribute-user-django-admin – helb Feb 23 '17 at 23:33
  • im using django 1.10.5 , ive looked at other questions and none of the answers helped – jalen201 Feb 24 '17 at 00:18
  • actually thanks that link is what I needed – jalen201 Feb 24 '17 at 00:18

1 Answers1

0

My solution for this while using Django 2.0 was to make sure that Django's Middleware came before django-user-accounts Middleware, and I would assume that is the case with all apps.

Simply changing the order around to this worked for me:

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",
]
Jordan Lashmar
  • 123
  • 3
  • 13