39
easy solution
just remove
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
from
MIDDLEWARE_CLASSES = (
...
...
)
in your project’s settings.py
then, it should work!
18
I was getting the same error. But i had forgotten to get into my VirtualEnv BEFORE running my server.
So make sure that from terminal you first activate virtualenv: source env/bin/activate
Then run: python manage.py runserver
- [Django]-User Registration with error: no such table: auth_user
- [Django]–bash: ./manage.py: Permission denied
- [Django]-How to delete old image when update ImageField?
14
As we can see in Django 1.8 release notes
django.contrib.auth.middleware.SessionAuthenticationMiddleware was
added in Django 1.7.
And you are using Django-1.6.5
in your virtual environment, hence the does not define
error.
Probably you have a newer version of Django installed in your “normal” environment and the server runs correctly. To fix this upgrade Django version inside your virtual environment (prior to updating Django be sure to activate your virtual environment!)
Now to add my two cents to the answers, because everything until now was repetition from ZZY and user1776955
If you run pip install -U Django
you will probably bump your version to something higher than 1.10 and then the following will apply:
In Django 1.10, session verification will be enabled regardless of
whether or not SessionAuthenticationMiddleware is enabled (at which
point SessionAuthenticationMiddleware will have no significance)
Hence it will be safe to delete it and if you update past 2.0 you will HAVE to delete it because Django 2.0 release notes state that:
Also a bit unrelated but relevant when updating to this version is that
Support for old-style middleware using settings.MIDDLEWARE_CLASSES is removed
As far as my experience goes it is enough to change MIDDLEWARE_CLASSES
to just MIDDLEWARE
and delete 'django.contrib.auth.middleware.SessionAuthenticationMiddleware'
from the list.
- [Django]-Distributing Django projects with unique SECRET_KEYs
- [Django]-How to expire Django session in 5minutes?
- [Django]-How to upload multiple images to a blog post in django
5
Refer to the doc, the Django in your active virtualenv must be Django 1.7. And:
This middleware must appear after django.contrib.auth.middleware.AuthenticationMiddleware in MIDDLEWARE_CLASSES
Does it solve your issue?
- [Django]-How do I get the object if it exists, or None if it does not exist in Django?
- [Django]-Django render_to_string missing information
- [Django]-How to paginate Django with other get variables?
4
run
python3 manage.py runserver
instead of
python manage.py runserver
or
./manage.py runserver
You can also edit the first line of manage.py replacing
\#!/usr/bin/env python
by
\#!/usr/bin/env python3
and then run ./manage.py runserver
(it seem to work, I don’t know if it’s authorized by django’s project)
- [Django]-Return the current user with Django Rest Framework
- [Django]-Is not JSON serializable
- [Django]-Django: Arbitrary number of unnamed urls.py parameters
2
I have created a Django project with Django 1.7 and tried to run it with Django 1.6.8. And I got the same error. I have just removed
‘django.contrib.auth.middleware.SessionAuthenticationMiddleware’,
from
MIDDLEWARE_CLASSES =
in my project’s settings.py.
And it works.
- [Django]-How to stop gunicorn properly
- [Django]-Nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
- [Django]-How to get Django and ReactJS to work together?
2
I encountered an issue similar to this today (Using OS X Mavericks).
First of all, do you have django installed to your base OS? Before using Virtualenv I was running Django directly on the OS. The main thing I noticed is I usually type django-admin, not django-admin.py. This was calling Django outside of the virtualenv, which was version 1.7.1.
Outside of my virtualenv I ran pip uninstall django, then went back into my Virtualenv. Running django-admin –version without a .py at the end returned “zsh: command not found: django-admin” (it used to return 1.7.1), however, running django-admin.py –version returned 1.6.5.
Check to make sure you aren’t accidentally bringing in an outside version of django directly from your OS, you may need to type django-admin.py
- [Django]-Saving ModelForm error(User_Message could not be created because the data didn't validate)
- [Django]-Django model fields validation
- [Django]-Django: allow line break from textarea input
2
It looks like you are using a version of django prior to version 1.7 (1.6.4 to be specific), and SessionAuthenticationMiddleware was not introduced until django 1.7. Hence the error
Documentation can be found here
https://docs.djangoproject.com/en/1.7/ref/middleware/#django.contrib.auth.middleware.SessionAuthenticationMiddleware
On the bottom right, you can choose the version of django. Select the appropriate version, and follow the tutorial specific to the version of django you are using.
- [Django]-How to migrate back from initial migration in Django 1.7?
- [Django]-Django storages aws s3 delete file from model record
- [Django]-How do I create sub-applications in Django?
1
So, I just ran a fresh install of my virtualenv and started the server, and now it’s working as expected. Problem solved.
- [Django]-ValueError: Missing staticfiles manifest entry for 'favicon.ico'
- [Django]-How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi?
- [Django]-Django middleware difference between process_request and process_view
0
Make sure that you are running $ source bin/activate from the root of your project. Otherwise just go ahead and wipe out your project and make a new one. And if you want to be a django dev get ready to make lots of virtualenv’s.
When working on separate branches for example, it’s sometimes easier to have two different virtualenv’s, etc and when you move to the server you’ll probably be running from a virtualenv as well. So it’s a good idea to get good at making them and going through the steps.
It’s easy to copy files between directories with the $ cp command.
- [Django]-Can I use a database view as a model in Django?
- [Django]-How to view corresponding SQL query of the Django ORM's queryset?
- [Django]-Problems with contenttypes when loading a fixture in Django
0
I am running Windows7/64 version, had the same error. Agreed with user1776955, who pointed out the version problem of Django.
so the easiest way to do is pointing to the Django-admin.py in shell. In my case, it is:
python env\scripts\django-admin.py startproject my_django15_project
- [Django]-Django post_save signals on update
- [Django]-Equivalent of PHP "echo something; exit();" with Python/Django?
- [Django]-Django: Reference to an outer query may only be used in a subquery
0
Just run it in Python 3 instead:
python3 manage.py runserver
If that would work, consider also applying some app migrations via: python3 manage.py migrate
.
- [Django]-Bypass confirmation prompt for pip uninstall
- [Django]-Django gives Bad Request (400) when DEBUG = False
- [Django]-What's the difference between CharField and TextField in Django?
-1
-
I have the same error:
File "C:\Users\DANI3\Envs\recetario\lib\site-packages\django\utils\module_loading.py", line 23, in import_string return getattr(module, class_name) django.core.exceptions.ImproperlyConfigured: WSGI application 'recetario.wsgi.application' could not be loaded; Error importing module: 'Module "social_django.middleware" does not define a "SocialAythExceptionMiddleware" attribute/class'
-
I corrected the error make this change:
'social_django.middleware.SocialAuthExceptionMiddleware',
- [Django]-How to filter empty or NULL names in a QuerySet?
- [Django]-What's the difference between CharField and TextField in Django?
- [Django]-How to access custom HTTP request headers on Django Rest Framework?