I've a middleware. I want to update the response object inside the middleware. Here is how I'm doing it.
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
It prints the correct response, but what the client receives, is without success
field. What am I missing?
Here is my 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'
]