I'm new to Django world and I'm trying to build a Django application with 2 function based views wherein one function/view should be able to call the other view. The reason I'm trying to do this is to reduce avoid writing the logic again which is available in my other API.
@api_view(['POST'])
def PerformActionOne(request):
result_one = PerformActionTwo(request)
result_two = DoSomethingElse(result_one)
return Response(result_two)
@api_view(['POST'])
def PerformActionTwo(request):
# Performs some calculation and returns rest_framework.response Response with some data in it
# result is a dictionary
result = Calculate()
return Response(result)
In the above code I'm getting an error in this line result_one = PerformActionTwo(request)
Error: Exception Type: AssertionError Exception Value:
Therequest
argument must be an instance ofdjango.http.HttpRequest
, notrest_framework.request.Request
.
I tried to look it up online and read documentation but I couldn't get a solution to this. I apologize if this is a duplicate question. Any leads on this will be greatly appreciated.
not for certain on this but it's possible that the django.http.HttpRequest
object is on the rest_framework.request.Request
object under the _request
param. Maybe try logging request._request
to see what type of object it is?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With