def index(request):
# 利用Django ORM中的values查找数据
content=Member.objects.filter(teleplay_id=tid).values('roomcomment_id','roomcomment_content').order_by('-roomcomment_time')
# 定义空字典
data_contents = {}
# 把查找到的数据放到列表里
datas = list(content)
# 给字典的key赋值
data_contents['attribute'] = '用户评论'
# 把列表放到字典的值中
data_contents['information'] = json.dumps(datas, cls=DjangoJSONEncoder, ensure_ascii=False)
return HttpResponse(json.dumps(data_contents))
Django返回json数据
最新推荐文章于 2023-07-27 14:10:47 发布