【发布时间】:2015-03-05 09:48:06
【问题描述】:
在我的一个 django 项目中,我设置了 django-rest-framework,使其返回以下类型的 json 响应:
{
"name": "John",
"last_name": "Smith",
"age": 35,
"dl_url": "[u'http://domain.com/file1', u'http://domain.com/file2']"
}
到目前为止一切顺利。
问题是我需要将dl_url 属性返回为 list 而不是 string 以便它变为:
{
"name": "John",
"last_name": "Smith",
"age": 35,
"dl_url": [u'http://domain.com/file1', u'http://domain.com/file2']
}
最好的方法是什么?
请注意,我将链接作为models.TextField(null=True, blank=True) 实例存储在我的models.py 中。
提前谢谢你。
【问题讨论】:
标签: python json django rest django-rest-framework