Django 1.10.6 - 中间件不起作用

时间:2017-05-09 08:50:06

标签: python django

我将我的应用程序从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

1 个答案:

答案 0 :(得分:2)

您可以通过继承django.utils.deprecation.MiddlewareMixin之类的

来制作旧式中间件
class OldMiddleware(MiddlewareMixin):
    #rest of code.