[英] How to return custom JSON in Django REST Framework
I am trying to return custom json with get_queryset
but always get 404 error
in response.
class TestViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = Test.objects.all()
serializer_class = TestSerializer
def get_queryset(self):
if self.request.method == "GET":
content = {'user_count': '2'}
return HttpResponse(json.dumps(content), content_type='application/json')
If I delete everything starting from def
I'll got correct response with standard json data. What I am doing wrong?