我有一个中间件。我想更新中间件内的响应对象。我正是这样做的。
class ErrorMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
if 'errors' in response.data:
response.data.update({'success': False})
print(response.data)
return response
它打印正确的响应,但客户端收到的是没有success
字段。我错过了什么?
这是我的settings.py
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',
'modules.utils.middleware.ErrorMiddleware'
]