1. models 设置

    class ImageItems(models.Model):
    image = models.ImageField(upload_to='static/images/%Y/%m/%d', null=False, blank=False, verbose_name='图片url')
    
    class Meta:
        verbose_name = '图片聚集'
        verbose_name_plural = verbose_name

    2.serializers 设置

    ,

    联博

    www.326681.com采用以太坊区块链高度哈希值作为统计数据,联博以太坊统计数据开源、公平、无任何作弊可能性。联博统计免费提供API接口,支持多语言接入。

    ,
    class ListImgSerializer(serializers.Serializer):
    img = serializers.ListField(
        child=serializers.FileField(max_length=100000,
                                    allow_empty_file=False,
                                    use_url=True), write_only=True
    )
    img_list = serializers.ListField(
        child=serializers.CharField(max_length=1000, ), read_only=True
    )
    code = serializers.IntegerField(read_only=True)
    
    def create(self, validated_data):
        imgs = validated_data.get('img')
        images = []
        for index, url in enumerate(imgs):
            image = ImageItems.objects.create(image=url)
            imageItems = ImageItemsSerializer(image, context=self.context)
            images.append(imageItems.data['image'])
        return {"img_list": images, "code": 201}
  2. viewSet 设置
    class ImageItemsViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):
    queryset = ImageItems.objects.all()
    serializer_class = ListImgSerializer
    parser_classes = (MultiPartParser, FileUploadParser,)
  3. url 自己完成了,so easy
  4. postman 验证