django - how to return two serializer in a response

Viewed 1427

I have two variable that i want to return: - serializer1.data and serializer2.data. I don't know how return 2 variable like : return Response(serializer1.data (and) serializer2.data, status=...). Any help is appreciated.

2 Answers

If you are only returning something like

return Response(serializer1.data)

And you want to add a second serializer data, the best way to don't change your response it to return:

return Response(serializer1.data + serializer2.data)

As ReturnList the first serializer data will be extended with the second. That way you will not have to iterate on endpoint's response.

Related