Rafael
Rafael

Reputation: 2731

Responding with a custom non simple object from a Django/Python API to the front

I'm a newbie building APIs with django/python

I built a dictionary object (it has lists inside other lists in it), and I want to send it to the front through one of the responses: JsonResponse, HttpResponse, etc.

What could be the way to do it?

I tried with several of them without a good response, I whether get an error, or a bad response

Thanks in advance

Rafael

Upvotes: 0

Views: 44

Answers (1)

Rafael
Rafael

Reputation: 2731

I got it

Just assume that you will send an array of objects, and the front end should access the first object it finds

    myResponse = []
    myResponse.append(myObject) 
    return HttpResponse(myResponse, status=200) // status is optional

Upvotes: 0

Related Questions