调用'is_valid()'会从序列化程序中删除数据

时间:2016-02-24 13:49:00

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

当我在序列化程序上调用is_valid时,传递给序列化程序的一些数据没有被保存。 serializer.initial_data中提供了files字段,但未在serializer.validated_data中保存。有什么想法吗?

串行:

class SomeSerializer(serializers.Serializer):
    email = serializers.EmailField()
    files = serializers.ListField(
        child=serializers.FileField()
        )

以下观点:

class SomeView(mixins.CreateModelMixin, generics.GenericAPIView):
    permission_classes = (permissions.IsAuthenticated,)
    serializer_class = SomeSerializer

    def post(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        email = serializer.validated_data["email"]
        files = serializer.validated_data.get("files")
        #Do something here
        return response

0 个答案:

没有答案