Wagtail - DRF Response() instead of JsonResponse()

216 Views Asked by At

I'm using Wagtail as a headless CMS / API, however instead of using the PagesAPIViewSet I've gone the route of overriding the serve() method as described here to fetch pages: https://docs.wagtail.org/en/stable/reference/contrib/routablepage.html

This has worked great since I can return a JsonResponse. The problem is that (as far as I understand), debug toolbar only works with the standard rest framework Response(), so I'm trying to find a way to return a DRF Response instead.

The error I'm getting is ".accepted_renderer not set on Response" How would I set the accepted renderer? This is roughly what I've got:

from rest_framework.response import Response
from wagtail.core.models import Page

class BasePage(Page, RoutablePageMixin):
    ....
    
    def serve(self, request, *args, **kwargs):
       context = self.get_context(request, *args, **kwargs) # Context where I serialize data to JSON etc.
       return Response(data=context['data'], status=status.HTTP_200_OK) ##Throws error, with JsonResponse() it works fine.
0

There are 0 best solutions below