为什么这不起作用?
从 wand.image 导入图像
def upload_to_cars(instance, filename):
blocks = filename.split('.')
ext = blocks[-1]
filename = "%s.%s" % (instance.name.replace(" ", "-"), ext)
with Image (filename=filename) as img:
img.type='grayscale';
img.save
return filename
class Cars(models.Model):
name = models.CharField(max_length=200)
image_file = models.ImageField(upload_to=upload_to_cars, null=True, blank=True)
我想在 django 中上传图像并对其进行灰度化。每次我运行这段代码时,它都会抛出一个
`解码此图像格式的委托'保时捷'@error/constitute.c/ReadImage/544
Porsche 是类的名称,应该是上传的图像文件的名称
帮助!