Django ImageField“上传有效图像。您上传的文件不是图像或损坏的图像。“ [英] Django ImageField "Upload a valid image. The file you uploaded was either not an image or a corrupted image."

查看:115
本文介绍了Django ImageField“上传有效图像。您上传的文件不是图像或损坏的图像。“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了PIL,但是当我尝试通过Django Admin为我的模型上传一个.png文件到一个图像字段时,我收到这个错误:

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."

其他图像类型工作正常。我已经尝试了几个不同的PNG文件。

Other image types work fine. I have tried several different PNG files.

我已经尝试在安装pypng,libpng-dev等之后重建PIL,并且在ubuntu服务器上。

I have tried rebuilding PIL after installing pypng, libpng-dev, etc.. and am on ubuntu server.

推荐答案

当您编译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:

apt-get install python-imaging

这篇关于Django ImageField“上传有效图像。您上传的文件不是图像或损坏的图像。“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆