我将我的应用程序从django 1.5移动到1.10并且我不知道为什么但是我的一个中间件不想工作(django 1.5没有问题)
来自设置的代码:
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.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'myApp.usersAuth.usersAuth',
]
中间件文件 - usersAuth.py:
class usersAuth():
def test(self, request):
request.session['firstName'] = 'test1'
request.session['secondName'] = 'test2'
我看到一个错误:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 82, in load_middleware
mw_instance = middleware(handler)
TypeError: this constructor takes no arguments
答案 0 :(得分:2)
您可以通过继承django.utils.deprecation.MiddlewareMixin
之类的
class OldMiddleware(MiddlewareMixin):
#rest of code.