8

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?

Sebastian Olsen
  • 10,318
  • 9
  • 46
  • 91
  • 1
    When you have errors after upgrading, it's worth checking the app's GitHub issues to see if it's a known problem. If that doesn't help and you ask a question on Stack Overflow, please post the *full* traceback. – Alasdair Sep 12 '16 at 20:52

2 Answers2

10

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
Adriaan Tijsseling
  • 2,025
  • 1
  • 18
  • 23
3

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

Alasdair
  • 298,606
  • 55
  • 578
  • 516