1

I have created a Django REST Framework endpoint that returns all the data I need for my page. I am trying to call this endpoint in one of my views and pass the response to the html template as part of the render.

when I print(response) it returns <function SetsIndividualData at 0x00000201656AB9D8>. All nothing is returned when I use {{ response.name }} in the html template. What am I missing here?

urls.py

path('sets/<str:setCode>/', setsIndividualPage),
path('sets/<str:setCode>/sets-individual-data/', SetsIndividualData.as_view(), name='sets-individual-data'),

views.py

def setsIndividualPage(request, setCode):
    response = SetsIndividualData.as_view()
    print(response)
    return render(request, "magic/sets-individual.html", {'response': response})

class SetsIndividualData(ListAPIView):
    serializer_class = SetSerializers

    def get_queryset(self):
        SQL_EXPRESSION = "CAST((REGEXP_MATCH(number, '\d+'))[1] as INTEGER)"
        setCode = self.kwargs.get('setCode', None)
        queryList = Set.objects.filter(code=setCode.upper()).prefetch_related(Prefetch('cards', queryset=Card.objects.extra(select={'int': SQL_EXPRESSION}).order_by('int', 'number')))
        return queryList
Ross
  • 2,463
  • 5
  • 35
  • 91

1 Answers1

3
response = SetsIndividualData.as_view()(request)
print(response)
lucutzu33
  • 3,470
  • 1
  • 10
  • 24