记得关注我哦
def valuesqueryset (request):
name = request.GET.get(‘xiaohuo,lu’)
valuesqueryset = Students.objects.filter(name=name).values(‘name’,‘age’,'sex)
此时为 valuesqueryset对象
if valuesqueryset:
valuesqueryset = list( valuesqueryset)#list
data = json.dumps( valuesqueryset)#json
retuen data
def queryset (request):
name = request.GET.get(‘xiaohuo,lu’)
queryset = Students.objects.filter(name=name)
此时为 queryset对象
if queryset:
data = serializers.serialize(“json”, queryset) #json
return data
Students.objects.filter(name=name).values(‘name’,‘age’,'sex)查询出来的valuesqueryset对象,首先list,然后json
Students.objects.filter()查询出来的queryset对象,直接serializers.serialize() 化成json