django 利用json处理前端页面数据,FLASK当中也同样

 
def create_company(request):
if request.user.is_superuser:
custom_list = Custom.objects.all()
compclass_list = Compclass.objects.all()
custom_list = serializers.serialize('json',custom_list)
compclass_list = serializers.serialize('json',compclass_list)
return render_to_response('sp/importspinfo.html',{'custom_list':json.dumps(custom_list),
'compclass_list':json.dumps(compclass_list)})
else:
return HttpResponse('请先登录')
 
var custom = {{ custom_list | safe }}
var obj = JSON.parse(custom);
alert(obj[0].pk);
alert(obj[0].fields.name)
alert(obj.length)