我如何接收 djano 中的词典列表?
你好,我正在开发一个 djago 项目,我想收到一个字典列表,如下所示: [{1:20}、{2:30}、{3:50}、......]
这里的key
是产品的id
,value
是price
下面的代码只是接收一个像这样的单个字典
{“id”:1,“价格”:20}
我想将其更改为我上面提到的样子,
list_of_objects = []
try:
id = int(request.payload.get("id"))
price = int(request.payload.get("price"))
list_of_objects.append({
"id" : id,
"price" : price
})
except ValueError:
return response.bad_request("Invalid price, %s, should be in whole dollars" % price)
但我不知道该怎么做 谢谢
Hello I am working on a djago project and I want to recieve a list of dictionaries just like this:[{1: 20}, {2:30}, {3: 50}, ......]
here the key
is the id of the product
and value
is price
And the code below is just receiving a single dictionary
like this{"id": 1, "price" : 20}
I want to change it to something look like I mentioned above
list_of_objects = []
try:
id = int(request.payload.get("id"))
price = int(request.payload.get("price"))
list_of_objects.append({
"id" : id,
"price" : price
})
except ValueError:
return response.bad_request("Invalid price, %s, should be in whole dollars" % price)
I don't know how to do it
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个
Try this
这应该可以解决问题:
This should do the trick:
这对我有用;不久前我也做了同样的事情。
我希望它也适合你。
This worked for me; I did the same thing a little while ago.
I hope it works for you too.