Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

object() takes no parameters in django 1.10

I'm trying to allow CORS in my app, so that my cross-domain javascript client can access my API, I've installed django-cors-headers. And I'm now trying to add the middleware:

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware', # Remove this and it works
    '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',
]

However this gives me a TypeError:

TypeError: object() takes no parameters

This worked fine before the django 1.10 update. Any ideas?

like image 651
Sebastian Olsen Avatar asked Sep 12 '16 19:09

Sebastian Olsen


2 Answers

If you have custom middleware and you've moved from MIDDLEWARE_CLASSES to MIDDLEWARE, then you need to update your middleware. Details on: this Django documentation page. TL;DR, subclass from MiddlewareMixin instead of object:

from django.utils.deprecation import MiddlewareMixin
class FOOMiddleware(MiddlewareMixin):
    pass
like image 136
Adriaan Tijsseling Avatar answered Oct 20 '22 04:10

Adriaan Tijsseling


This issue says that django-cors-headers is no longer supported, and suggests using django-cors-middleware instead.

like image 44
Alasdair Avatar answered Oct 20 '22 05:10

Alasdair