serializer.save()不保存在Django rest中

时间:2019-01-28 09:25:53

标签: django django-rest-framework django-serializer

我的APIView在读取和写入地点名称时遇到问题。这是我的观点,

class pList(APIView):
    def get(self,request):
        e = placename.objects.all()
        ser = placeSerializer(e,many=True)
        return Response(ser.data)

    def post(self,request):
        serializer = placeSerializer(data=request.data, many=True)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

和我的序列化器

class placeSerializer(serializers.ModelSerializer):
    class Meta:
        model = placename
        fields = ('em_name')

get方法工作正常,但是当我尝试POST时,我得到一个空set([])。我在这里做什么错了?

PS:我是DRF的新手。

0 个答案:

没有答案