我在views.py里面打印這個對象都能成功打印:def inherit(request): print(Inheritinfo.objects.filter()[0]) #這里都可以成功打印出來 return render(request, 'inherit.html') 但是為什么在api視圖里面就報錯呢?報錯:AttributeError: 'function' object has no attribute 'objects' class InheritinfoSerializer(serializers.ModelSerializer): class Meta: model = Inheritinfo fields = '__all__' depth = 1@api_view(['GET', 'POST'])def Inheritinfo(request): if request.method == 'GET': print(Inheritinfo.objects.filter()[0]) #在這一句報的錯 postinfo = Inheritinfo.objects.filter()[0] serializer = InheritinfoSerializer(postinfo) return Response(serializer.data)
django為什么在api視圖里就找不到數據呢?
茅侃侃
2018-12-11 17:27:32