python 将Django QuerySet作为JSON响应返回的示例(Django 1.7)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 将Django QuerySet作为JSON响应返回的示例(Django 1.7)相关的知识,希望对你有一定的参考价值。

# Get the objects from the database
rawData = Launch.objects.all()

# Create array
json_res = []

# Iterate over results and add to array
for record in rawData: 
  json_obj = dict(name = record.name)
  json_res.append(json_obj)

# Return the results   		
return HttpResponse(json.dumps(json_res), content_type='application/json')

以上是关于python 将Django QuerySet作为JSON响应返回的示例(Django 1.7)的主要内容,如果未能解决你的问题,请参考以下文章