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?

2

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.