# 问题的起因是我后端设置如果参数为空不传。结果前端传给我空字符串。遂二次处理。
def create(self, request, *args, **kwargs): try: request.data._mutable = True except Exception as e: logger.info(e) finally: for item in list(request.data): # 防止序列化校验异常 if not request.data[item] and request.data[item] != 0: request.data.pop(item) 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)