我在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)
添加回答
举报
0/150
提交
取消