Bogi Kovacs
Bogi Kovacs

Reputation: 13

Is there a way to return 3 files together with some data calculations from one Django request?

I have a Django request doing some ML calculations. The request takes 3 files as input and generates several files as an output together with some temperature data calculations that I need, therefore I need to return content type = "multipart/form-data" as a Django Response.

If I try using rest_framework.response then I get: TypeError: keys must be str, int, float, bool or None, not tuple

from rest_framework.response import Response
return Response(thermal_response["data"], status=thermal_response["statusCode"])

If I try using JSONResponse I get: TypeError: Object of type ndarray is not JSON serializable

from django.http import JsonResponse
JsonResponse(thermal_response["data"], safe=False)

Upvotes: 0

Views: 57

Answers (1)

Amir Hallaj
Amir Hallaj

Reputation: 30

You cannot implicity convert ndarray into Json. try tolist method, which allows you to convert an array to a list:

JsonResponse(thermal_response["data"].tolist(), safe=False)

Upvotes: 0

Related Questions