Here is my Source Code推荐答案您可以删除序列化程序中的其他字段,默认情况下models.ImageField将使用serializer.ImageField.You can delete additional field in your serializer, models.ImageField will use serializer.ImageField by default.class ImageSerializer(serializers.ModelSerializer): class Meta: model=ImageUploadModel fields=('usr_id','upImg','caption')它应该可以正常工作,您的视图代码是正确的您也可以使用generics.CreateAPIView减少代码.It should just work, your view code is correctYou could also use generics.CreateAPIView to reduce a code.class imageuploadView(generics.CreateAPIView): queryset = ImageUploadModel.objects.all() serializer_class = ImageSerializer如果它不起作用,请用serializer.errors更新您的答案,您可以在else情况下进行检查If it will not work, please update your answer with a serializer.errors, you can check it in else case 这篇关于我无法使用Django Rest-framework上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-27 20:41