[英]Responding with a custom non simple object from a Django/Python API to the front
I'm a newbie building APIs with django/python我是使用 django/python 构建 API 的新手
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.我建立了一个字典 object(它在其他列表中有列表),我想通过响应之一将它发送到前面:JsonResponse、HttpResponse 等。
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拉斐尔
I got it我知道了
Just assume that you will send an array of objects, and the front end should access the first object it finds假设你将发送一个对象数组,前端应该访问它找到的第一个 object
myResponse = []
myResponse.append(myObject)
return HttpResponse(myResponse, status=200) // status is optional
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.