[Answered ]-Django.template.response.ContentNotRenderedError: The response content must be rendered before it can be iterated over

1👍

The get_queryset is supposed to return, as the name suggests… a QuerySet, not a response object. You can try to pass a list, since it is iterable as well, but likely if pagination, serialization, etc. is performed, it will eventually fail.

You can implement the list method yourself, with:

class OrderMetrics(generics.ListCreateAPIView):
    queryset = Order.objects.all()
    serializer_class = OrderSerializer

    def list(self, request, *args, **kwargs):
        context = [
            {
                'data': round(current_total),
                'percent': abs(total_delta_percentage),
            },
            {
                'data': current_count,
                'percent': abs(average_delta_percentage),
            },
        ]
        return Response(context, status=status.HTTP_200_OK)

but it is unclear to me then why you use a GenericAPIView with a model and a serializer, since you will only use these for the create use case, and it is a bit odd to create Orders in an endpoint that shows metrics of orders.

Leave a comment