【发布时间】:2016-04-21 22:06:10
【问题描述】:
我需要将 JSON 数据转换为 django 模型。
这是我的 JSON 数据
{
"data": [
{
"id": "20ad5d9c-b32e-4599-8866-a3aaa5ac77de",
"name": "name_1"
},
{
"id": "7b6d76cc-86cd-40f8-be90-af6ced7fec44",
"name": "name_2"
},
{
"id": "b8843b1a-9eb0-499f-ba64-25e436f04c4b",
"name": "name_3"
}
]
}
这是我的 django 方法
def get_titles():
url = 'http://localhost:8080/titles/'
r = requests.get(url)
titles = r.json()
print(titles['data'])
我需要的是转换为模型并传递给模板。请告诉我如何将 JSON 转换为模型。
【问题讨论】:
标签: python json django python-2.7 django-models