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
|
More like this
- Ajax API class by kcarnold 3 years, 8 months ago
- Ajax error handling by kcarnold 3 years, 8 months ago
- SerializedObjectField by dominno 1 year, 11 months ago
- JSON encode ISO UTC datetime by japerk 2 years, 10 months ago
- Extended JSON encoder by kcarnold 3 years, 8 months ago
Comments
hm - one problem here is it should also encode lists and tuples, no?
#