0

I've searched stack overflow and the internet for a solution to call a django restframework ListAPIView from anotehr django restframework APIView.

I've tried:

class ViewA(APIView):
   def get(request):
        response = ViewB.as_view({'get':'list'})(request)
        print response.render()
        # do other things with the response

However, I get the error:

    response = SubsidiariesStatisticsView.as_view({'get': 'list'})(request)
TypeError: as_view() takes exactly 1 argument (2 given)

How do I pass in a request from viewA to viewB and get a response? Also, class ViewB has a get_serializer_context method. How do I call that from ViewA?

2 Answers 2

1

This is not a very nice practice, and also a overkill. instead just write a function that does what you want and use it in both views.

Sign up to request clarification or add additional context in comments.

1 Comment

I think you're right. Will probably do this. Thanks!
1

I had similar case before and by following this issue from the official repo, changing my DRF View to ViewSet solved my problem. Just try modifying your views to extend from ViewSet or GenericViewSet or something.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.