object() takes no parameters in django 1.10

£可爱£侵袭症+ 提交于 2019-11-28 07:37:03

问题


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?


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/39457381/object-takes-no-parameters-in-django-1-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!