Django ImageField "Upload a valid image. The file you uploaded was either not an image or a corrupted image."
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, et开发者_开发百科c.. and am on ubuntu server.
This issue was solved by using pip to install "pillow" instead of "pil" which allows easy deployment to virtualenv.
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
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:
JPEG_ROOT = None
and change it to
JPEG_ROOT = '/usr/lib/i386-linux-gnu/'
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, but setup.py
will look in JPEG_ROOT
for libpng
too.
精彩评论