2017-05-09 45 views
0

我正在將我的應用程序從django 1.5移動到1.10,我不知道爲什麼,但我的一箇中間件不想工作(在django 1.5中沒有問題)從設置Django 1.10.6 - 中間件不工作

代碼:

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

做舊風格的中間件來看看https://docs.djangoproject.com/en/1.11/topics/http/middleware/#upgrading-middleware – itzMEonTV

回答

2

您可以通過繼承django.utils.deprecation.MiddlewareMixin

class OldMiddleware(MiddlewareMixin): 
    #rest of code.