Django-rest-framework: drf override Response() for custom response

Created on 3 Apr 2019  路  1Comment  路  Source: encode/django-rest-framework

I'm using DRF and to return response, I used Response() which located at from rest_framework.response import Response

To make custom response, first, I copied all of the source to custom file.

And in my views, I changed Response() to my own file.

But when I running django server and access via web, it through errors.

AssertionError: .accepted_renderer not set on Response

I just copied original Repsonse() and re-use it.

Why it occur errors?

Purpose of custom response is I want to add more argument that something likes cursor for pagination.

As you know that in original Response, takes 6 arguments.

def __init__(self, data=None, status=None,
             template_name=None, headers=None,
             exception=False, content_type=None):

And return it in def rendered_content(self), line of ret = renderer.render(self.data, accepted_media_type, context)

So my scenario is, add cursor to __init__ and pass through it to renderer.render().

Any problem with my way?

Thanks.

>All comments

The discussion group is the best place to take this discussion and other usage questions. Thanks!

Was this page helpful?
0 / 5 - 0 ratings