1 2 3 4 5 6 7 8 9 10 | from snippet 801 import JsonResponse
class JsonEncodingMiddleware(object):
'''If a view returns a dict, encode it as JSON.
This should be the last middleware in MIDDLEWARE_CLASSES.'''
def process_response(self, request, response):
if isinstance(response, dict):
return JsonResponse(response)
else:
return response
|
Comments