0

I'm using Django with rest_framework and in my views I'm using the rest_framework.viewsets, I stopped rest_framework to show it's fancy interface using:

REST_FRAMEWORK = {
    'DEFAULT_RENDERER_CLASSES': ('rest_framework.renderers.JSONRenderer'),
}

But now Django is rendering the JSON response Django JSON response

I want it always to return Raw Data

How can I do that?

Mohammad
  • 90
  • 7
  • 1
    Django is **not** rendering that interface, it's your browser that does that for json. Check [How can you disable the new JSON Viewer/Reader in Firefox Developer Edition?](https://stackoverflow.com/questions/34399282/how-can-you-disable-the-new-json-viewer-reader-in-firefox-developer-edition) – Abdul Aziz Barkat Feb 07 '21 at 06:24
  • You answered my 10 hours of search – Mohammad Feb 07 '21 at 09:51

1 Answers1

3

You can try writing your custom renderer.

Example:

from django.utils.encoding import smart_text
from rest_framework import renderers


class PlainTextRenderer(renderers.BaseRenderer):
    media_type = 'text/plain'
    format = 'txt'

    def render(self, data, media_type=None, renderer_context=None):
        return smart_text(data, encoding=self.charset)

The default charset with a custom renderer is UTF-8. If you want to change that you can read more about that here https://www.django-rest-framework.org/api-guide/renderers/

Rahul Arora
  • 131
  • 2
  • 1
    Thanks my friend . It turned out to be a Firefox thing, not Django. But it also a good solution despite the fact that the returned data is OrderedDict. – Mohammad Feb 07 '21 at 09:56