I’ve just recently hit this problem. This solution doesn’t use the Django Rest Framework Response, but if your server just returns JSON this solution might work for you.
New in django 1.7 or greater is the JSONResponse response type.
https://docs.djangoproject.com/en/3.0/ref/request-response/#jsonresponse-objects
In the middleware you can return these responses without having all the “No accepted renderers” and “Response has no attribute encode” errors.
It’s very similar format to the DRF Response
The import is as follows:
from django.http import JsonResponse
And how you use it:
return JsonResponse({'error': 'Some error'}, status=401)
Hopefully this helps you out!