36π
In Django 2.2.3, activating middlewears in settings is done using the variable MIDDLEWARE
not MIDDLEWERE_CLASSES
, check the docs here.
So simply change the variable in your settings.py
from MIDDLEWARE_CLASSES
to MIDDLEWARE
.
Most likely this issue occurred due to creating a project with a global django
package that had was of version < 2, and then running manage.py runserver
with a virtualenv that has local django
>= 2
10π
Rename variables in settings.py
, or add this:
MIDDLEWARE = MIDDLEWARE_CLASSES
to settings.py
because new Django triggers errors above based on checks like this:
if not _contains_subclass(
'django.contrib.auth.middleware.AuthenticationMiddleware',
settings.MIDDLEWARE
):
errors.append(checks.Error( ...
- [Django]-Serialize queryset in Django rest framework
- [Django]-Creating a dynamic choice field
- [Django]-AttributeError: 'module' object has no attribute 'tests'
7π
Change setting.py as pic shows
Change setting.py
# MIDDLEWARE_CLASSES = [
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.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Also See: From CSDN
- [Django]-You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application
- [Django]-How do I drop a table from SQLite3 in DJango?
- [Django]-Django: Implementing a Form within a generic DetailView
5π
1) Go to settings.py of your project
2) Cut these three lines from MIDDLEWARE_CLASSES :
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
3) Now paste the code given below right after MIDDLEWARE_CLASSES :
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
]
Will look like this:
- [Django]-Django form resubmitted upon refresh
- [Django]-What does on_delete do on Django models?
- [Django]-Django: Calculate the Sum of the column values through query
0π
change like it and keep the both ke MIDDLEWARE_CLASSES
and MIDDLEWARE
classes
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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',
]
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
]
- [Django]-Django: best practice way to get model from an instance of that model
- [Django]-Django models | get specific columns
- [Django]-Duplicate column name
0π
If you have a custom middleware, try to import it in manage.py shell
. Sometimes Django can blame other middlewares when it cannot import yours (because of not installed dependency for example).
- [Django]-Django redirect to view
- [Django]-What's the best way to handle Django's objects.get?
- [Django]-Django static page?