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

后端 未结 2 1725
情深已故
情深已故 2020-12-15 20:30

While I am calling Django url in ajax, getting below error

AssertionError: .accepted_renderer not set on Response.

This is my co

相关标签:
2条回答
  • 2020-12-15 21:03

    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')
    
    0 讨论(0)
  • 2020-12-15 21:08

    In addition to the accepted answer by @DavidLam it could also be that an error was thrown in your view/handler4xx/handler5xx and you've not caught it appropriately.

    0 讨论(0)
提交回复
热议问题