How to programmatically call a Django Rest Framework view within another view?

前端 未结 5 1385
醉酒成梦
醉酒成梦 2020-12-04 17:38

I have the following generic class based views built with Django Rest framework (DRF)

class ExampleDetail(generics.RetrieveUpdateDestroyAPIView):
    queryse         


        
5条回答
  •  攒了一身酷
    2020-12-04 18:18

    As of Django 2.2 and DRF 3.9.2 I am able to get response using below code.

    response = UserItemsApiView.as_view()(request=request._request).data
    

    Above example solves below issues:

    • The request argument must be an instance of django.http.HttpRequest, not rest_framework.request.Request
    • Instead of content, using data attribute gave me result from that view.

提交回复
热议问题