How to resolve AssertionError: .accepted_renderer not set on Response in django and ajax

If you're using a function based view, then this issue usually means you forgot to add the @api_view and the @renderer_classes decorator to your view.

Example:

from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import JSONRenderer, TemplateHTMLRenderer

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def get_assessment_count(request):
    [...]
    data = {'count': queryset.count()}
    return Response(data, template_name='assessments.html')

Tags:

Ajax

Django