标签:
好方便啊……list什么的一下都变成json了呢!
import json from django.core.serializers.json import DjangoJSONEncoder def main(request): output = [] ucc = Userformulateplan.objects.all() for i in ucc: plan = {} plan[‘username‘] = i.username.username plan[‘cname‘] = i.pid.cid.cname plan[‘deadline‘] = i.pid.deadline output.append(plan) t = loader.get_template("main.html") c = Context({"output" : json.dumps(output, ensure_ascii=False, cls=DjangoJSONEncoder)}) #第二个参数使中文字符不会被转成ascii码,第三个参数使日期可以正常转换,需要第二个import response = HttpResponse(t.render(c)) return response
标签:
原文地址:http://www.cnblogs.com/Apro/p/5069255.html