我正在尝试将图像添加到我的 Django 应用程序中的模型中。
模型.py
class ImageMain(models.Model):
"""This is the Main Image of the product"""
product = models.ForeignKey(Product)
photo = models.ImageField(upload_to='products')
在开发模式下,每次我尝试通过 Django admin 上传图像时,我都会不断收到:
Upload a valid image. The file you uploaded was either not an image or a corrupted image.
我尝试上传的 jpg 可以使用 os X Preview 查看,因此它似乎是有效的。
似乎问题在于 Python 图像库无法将其识别为图像。为什么使用有效图像会发生这种情况?
PIL 已安装,通过 Django shell 进行验证。