-
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 配置
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}
- viewSet 配置
class ImageItemsViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet): queryset = ImageItems.objects.all() serializer_class = ListImgSerializer parser_classes = (MultiPartParser, FileUploadParser,)
- url 自己完成了,so easy
- postman 验证
相关文章
- 02-19.net core实现单文件上传、多文件上传、js提交实现文件上传、图片预览
- 02-19利用FormData,实现上传图片的添加和删除功能
- 02-19利用FormData,实现上传图片的添加和删除功能
- 02-19vue-用formData实现单张图片上传
- 02-19vue-element-admin el-upload组件实现图片上传
- 02-19Django 后台保存 uni-app 前端上传的图片
- 02-19tinymce实现ctrl+v粘贴word图片并上传
- 02-19xhEditor 实现ctrl+v粘贴图片并上传、word粘贴带图片
- 02-19TinyMCE实现WORD粘贴图片自动上传
- 02-19TinyMCE如何能实现直接粘贴把图片上传到服务器中