I am trying to return the JsonResponse from another function but I get the following error from DRF:
AssertionError: Expected a
Response,HttpResponseorHttpStreamingResponseto be returned from the view, but received a<class 'NoneType'>
Here is my code
class SignedURL(GenericViewSet):
queryset = fileUpload.objects.all()
serializer_class = fileUploadSerializer
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
function1(request)
function2(request)
function3(request) <-- must quit here if this function has an error and return the JSONresponse of this function.
function4(request)
def function1(request):
return JsonResponse(
{
"message": "Pass",
},
status=status.HTTP_400_BAD_REQUEST,
How can I return the JsonResponse from another function without writing return JsonResponse in the def create itself?
Further clarification:
I have ten different functions with ten different JsonResponse.
ie, function2,function3...function10. If, for example, function 4 fails, I would like to return the JsonResponse immediately from that function and not proceed further with the other functions after function 4 within the create call.