How to pass django rest framework response to html

0 votes

How to pass django restframework response for any request to html. Example: A list which contains objects, and html be articles.html.

I tried by using rest framework Response :

data= {'articles': Article.objects.all() }
return Response(data, template_name='articles.html')

I am getting this error :

""" AssertionError at /articles/

.accepted_renderer not set on Response """

How to fix this error?

Jun 25, 2020 in Python by kartik
• 37,510 points
5,076 views

1 answer to this question.

0 votes

Hello @kartik,

You need to use an @api_view decorator to display properly. I've seen this particular error happen for this exact reason (missing API View declaration in function based views).

from rest_framework.decorators import api_view
# ....

@api_view(['GET', 'POST', ])
def articles(request, format=None):
    data= {'articles': Article.objects.all() }
    return Response(data, template_name='articles.html')

Hope this is helpful!

answered Jun 25, 2020 by Niroj
• 82,880 points

Related Questions In Python

0 votes
1 answer

how to download and install Django rest framework?

To install Django, you can simply open ...READ MORE

answered Apr 24, 2018 in Python by Christine
• 15,790 points
1,605 views
0 votes
1 answer

How to PATCH a single field using Django Rest Framework?

Hello @kartik, Serializers allow partial updates by specifying partial=True when initializing ...READ MORE

answered Jun 25, 2020 in Python by Niroj
• 82,880 points
14,805 views
0 votes
1 answer

How to add annotate data in django-rest-framework queryset responses?

Hello @kartik, The queryset returned from get_queryset provides ...READ MORE

answered Jun 25, 2020 in Python by Niroj
• 82,880 points
5,840 views
0 votes
1 answer

How to secure APIs for Registration and Login in Django Rest Framework?

Hello @kartik, you cannot have an authentication system ...READ MORE

answered Jun 25, 2020 in Python by Niroj
• 82,880 points
2,661 views
0 votes
1 answer

How to return the current user with Django Rest Framework?

Hello @kartik, The best way is to use ...READ MORE

answered Jun 25, 2020 in Python by Niroj
• 82,880 points
11,480 views
0 votes
1 answer

How to return custom JSON in Django REST Framework?

Hello @kartik, There are 2 ways to custom ...READ MORE

answered Jun 25, 2020 in Python by Niroj
• 82,880 points
10,794 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP