3

I started my virtualenv. Then started my server via python manage.py runserver. I ended up visiting my django site and getting the following error.

(venv)N$ python manage.py runserver
Validating models...

0 errors found
June 11, 2015 - 19:27:19
Django version 1.6.5, using settings 'nirsite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/Library/Python/2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "/Library/Python/2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    self.load_middleware()
  File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 45, in load_middleware
    mw_class = import_by_path(middleware_path)
  File "/Library/Python/2.7/site-packages/django/utils/module_loading.py", line 31, in import_by_path
    error_prefix, module_path, class_name))
ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class

I have already checked out this Stackoverflow, and I couldn't resolve the problem with any of these answers. Seeing as the venv is set up properly and I don't think getting rid of any of the Middlewares makes sense.

I can provide more information upon request.

Update:

Okay this looks like a problem with my virtualenv. After I started this virtualenv, I did pip install django within it, but now if I type that that within it again, I get the following:

Requirement already satisfied (use --upgrade to upgrade): django in /Library/Python/2.7/site-packages

This isn't pointing to my virtualenv I think, so I am guessing this is a problem. Why didn't the venv I was in install django? How can I fix this? And not run into the problem next time around?

Community
  • 1
  • 1
ApathyBear
  • 9,057
  • 14
  • 56
  • 90
  • Did you tried removing 'django.contrib.sessions.middleware.SessionMiddleware', from your project settings.py in MIDDLEWARE_CLASSES class – coder3521 Jun 11 '15 at 20:03
  • Yes, I still receive the same error. And I don't see why I would have to remove it? If I remove **ALL** of them however, it seems to fix the error from appearing. Though, I don't really want to do this. – ApathyBear Jun 11 '15 at 20:07
  • The traceback suggests that it does not search for the Django installation within your virtualenv but rather from a version installed in the library of your system Python at `/Library/Python/2.7/...`. Did installing Django into the virtualenv went without problems? Do you still see the output of that `pip install django`? – sthzg Jun 11 '15 at 20:12
  • @sthzg I have updated my question with more information. – ApathyBear Jun 11 '15 at 20:27
  • When you activate your virtualenv and type `which pip` and `which python`, do these point to the correct path of your virtualenv? If yes, please try installing Django with `pip install --ignore-installed Django`. This should ignore if Django is already installed system wide ([docs](https://pip.pypa.io/en/stable/reference/pip_install.html#cmdoption-I)) and install it to your virtualenv. After that you could deactivate and reactivate your virtualenv and test it again. – sthzg Jun 12 '15 at 10:43
  • When I run `which pip` AND `which python` it points to `/usr/bin/python`. When I run `pip install --ignore-installed` within my virtual env, it out puts: `Successfully installed Django-1.6.5.` That doesn't seem right :/ I even tried to specify Django=1.8 and it gave me a `ValueError: ('Expected version spec in', 'Django=1.8', 'at', '=1.8')` – ApathyBear Jun 12 '15 at 21:37

2 Answers2

2

for Django 2.0 and above

SessionAuthenticationMiddleware was removed in Django 2.0 (see Django 2.0 release notes here)

just remove it from MIDDLEWARE_CLASSES

posting it here because I faced the same problem when upgrading to Django 2

Aarif
  • 1,595
  • 3
  • 17
  • 29
1

You wrote : Django 1.8

But look at log : Django version 1.6.5

There is the problem - check django version in virtualenv or may be you just forgot activate virtualenv

Vadim Shatalov
  • 339
  • 2
  • 5