我是新的
model.py
class Profile(models.Model):
owner = models.OneToOneField(User, related_name='profile')
photo = models.ImageField(null=True, blank=True, upload_to='profiles/images/', max_length=255)
serializer.py
class ProfileSerializer(serializers.ModelSerializer):
class Meta:
model = Profile
fields = ('id', 'owner', 'photo')
views.py
class ProfileViewSet(viewsets.ModelViewSet):
queryset = Profile.objects.all()
serializer_class = ProfileSerializer
permission_classes = [permissions.IsAuthenticated, IsStaffOrTargetProfile]
如果我尝试:
curl -X PUT http://url -H 'Authorization: Token cffca5718f98bd1d80a3247be7b0bd51c2f28444' -H 'Content-Type:multipart/form-data' -F "photo=@/path/filename.jpg;type=image/jpeg" -F "owner=13"
我收到服务器错误(500)。问题是imageFiled,因为项目在没有图像存档的情况下被正确修改。 我只是通过DRF的html形式没有问题,为什么?
拜托,谁能告诉我有什么问题以及如何解决? 感谢