perform_createt中的序列化程序来自哪里?

时间:2016-07-16 13:16:48

标签: django-rest-framework

虽然序列化程序作为参数在perform_create方法中传递,但不清楚它从哪里传递。任何人都可以解释序列化参数传递的位置及其工作原理吗?

 class SnippetList(generics.ListCreateAPIView):
    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)

1 个答案:

答案 0 :(得分:1)

它来自CreateModelMixin

def create(self, request, *args, **kwargs):
    serializer = self.get_serializer(data=request.data)
    serializer.is_valid(raise_exception=True)
    self.perform_create(serializer)
    headers = self.get_success_headers(serializer.data)
    return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)