Django ImageField“上传有效图像。您上传的文件要么不是图像,要么是损坏的图像。”
我安装了 PIL,但是每当我尝试通过我的模型的 Django Admin 将 .png 文件上传到图像字段时,我会收到此错误:
“上传有效图像。您上传的文件不是图像或已损坏”图像。”
其他图像类型工作正常。我尝试过几个不同的 PNG 文件。
我在安装 pypng、libpng-dev 等后尝试重建 PIL,并且在 ubuntu 服务器上。
I have PIL installed, however whenever I try to upload a .png file to an image field through the Django Admin for my model, I get this error:
"Upload a valid image. The file you uploaded was either not an image or a corrupted image."
Other image types work fine. I have tried several different PNG files.
I have tried rebuilding PIL after installing pypng, libpng-dev, etc.. and am on ubuntu server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过使用 pip 安装“pillow”而不是“pil”解决了这个问题,这样可以轻松部署到 virtualenv。
This issue was solved by using pip to install "pillow" instead of "pil" which allows easy deployment to virtualenv.
当你编译PIL时,应该会说它是否编译有PNG支持,但如果你自己安装有问题,我建议你使用ubuntu自带的版本。它的名字很奇怪,但很容易安装:
When you compile PIL it should say if it has been compiled with PNG support or not, but if you have problems installing it yourself, I would recommend that you use the version that comes with ubuntu. It's strangely named but easily installed with:
我发现在 Ubuntu 上构建 PIL 可能会导致问题,因为
libpng
位于非标准位置,PIL 找不到它。在 PIL 下载到的文件夹中,编辑
setup.py
。找到以下行:并将其更改为
然后重建 PIL 并检查包含 PNG 支持的末尾附近的消息。
我知道当您想要添加 PNG 支持时修改
JPEG_ROOT
很奇怪,但是setup.py
会在JPEG_ROOT
中查找libpng< /代码>也是如此。
I have found that building PIL on Ubuntu can cause problems because
libpng
is in a non standard location, and PIL can't find it.In the folder that PIL has been downloaded to, edit
setup.py
. Find the following line:and change it to
then rebuild PIL and check for the messages near the end that PNG support is included.
I know it's odd to modify
JPEG_ROOT
when you want to add PNG support, butsetup.py
will look inJPEG_ROOT
forlibpng
too.