我想在Django 1.10項目中使用我自己的第一個中間件。目前運行到以下錯誤嘗試在Django中定義中間件時丟失位置參數錯誤
TypeError: init() missing 1 required positional argument: 'get_response'
我已經在middleware.py
定義的中間件是這樣的:
從zeon.utils導入RequestLogThread
class StartRestEndPointMiddleWare(object):
def __init__(self, get_response):
self.get_response = get_response
# One-time configuration and initialization.
def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.
request.request_log_id = RequestLogThread('send_contact', request.data).start()
response = self.get_response(request)
# Code to be executed for each request/response after
# the view is called.
return response
我迷失試圖找出什麼錯了,因爲一切似乎都是按照doc。我真的很感激任何提示。
UPDATE: 我把它放到middle_classes:
MIDDLEWARE_CLASSES = [
'zeon.middleware.StartRestEndPointMiddleWare',
]
您是將它放在'MIDDLEWARE'字典還是放在'MIDDLEWARE_CLASSES'字典中? – Blender
我已根據您的問題 –