91π
To resolve this go to settings.py
where there is new-style MIDDLEWARE
(introduced in Django 1.10)
Change that to old-style MIDDLEWARE_CLASSES
72π
I found the answer. The variable name on:
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',
]
MIDDLEWARE
is the new-style configuration introduced in Django 1.10. Change the name to MIDDLEWARE_CLASSES
and now it works.
So now the code is:
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.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
- [Django]-Django staticfiles not found on Heroku (with whitenoise)
- [Django]-Django CSRF check failing with an Ajax POST request
- [Django]-In a django model custom save() method, how should you identify a new object?
42π
In case anyone is having this problem with Django 2.0, the following configuration with new-style MIDDLEWARE
seems to work (docs here):
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',
]
- [Django]-Django delete superuser
- [Django]-Virtualenv and source version control
- [Django]-IntegrityError duplicate key value violates unique constraint β django/postgres
26π
In case anyone is having the same problem in django 2.0.2 or later,
just update
MIDDLEWARE_CLASSES = (
'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',
'django.middleware.security.SecurityMiddleware',
)
with
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',
]
It worked for me cause i created my project with
django 1.0.x but later updated to django 2.0.2
- [Django]-Speeding up Django Testing
- [Django]-Difference between filter with multiple arguments and chain filter in django
- [Django]-Django rest framework, use different serializers in the same ModelViewSet
16π
You should not change MIDDLEWARE to MIDDLEWARE_CLASSES. What happens here is more likely that you created the app with django 1.10 and now you are running it with 1.9 or a previous version.
Make sure you use a specific version of django(and all other libraries) so your project doesnβt break when deploying or running on different machines.
If you have a stable codebase simply run:
pip freeze > requirements.txt
And then when deploying or setting up a new env just do:
pip install -r requirements.txt
You should always consider using fixed versions of your libraries(and hopefully virtual envs), and when upgrading dependencies test each version change.
- [Django]-Django β Render the <label> of a single form field
- [Django]-Django models avoid duplicates
- [Django]-Pass extra arguments to Serializer Class in Django Rest Framework
3π
I had a similar error in my production server and thanks to sentryβs breadcrumbs I saw that the error that was raising had to do with my settings, especially the ALLOWED_HOSTS.
Django version 1.10.8 with python 2.7.
My previous settings:
ALLOWED_HOSTS = ['0.0.0.0',
'beta.mydomain.co.uk',
'mydomain.co.uk',
'www.mydomain.co.uk',
'alpha.mydomain.co.uk']
Sentry Breadcrumbs screen shot:
After that I looked around and found this:
A value beginning with a period can be used as a subdomain wildcard:
β.example.comβ will match example.com, www.example.com, and any other
subdomain of example.com.
Link to Django official docs
So my final settings that solved my problem:
ALLOWED_HOSTS = ['0.0.0.0',
'mydomain.co.uk',
'www.mydomain.co.uk',
'.mydomain.co.uk']
Hope this was useful π
- [Django]-Django optional URL parameters
- [Django]-Can you give a Django app a verbose name for use throughout the admin?
- [Django]-Nginx doesn't serve static
2π
My solution was that my Django ver. was 1.9 I reinstalled back to 1.10 without changing MIDDLEWARE to MIDDLEWARE_CLASSES.
- [Django]-Combining Django F, Value and a dict to annotate a queryset
- [Django]-Cannot apply DjangoModelPermissions on a view that does not have `.queryset` property or overrides the `.get_queryset()` method
- [Django]-How do you detect a new instance of the model in Django's model.save()