Django后台ADMIN模块中无法上传图片的问题

一直报如下错误:

 

Upload a valid image. The file you uploaded was either not an image or a corrupted image.

 

由于是PYTHON新手,GOOGLE BAIDU都搜遍了,无果。 最后找了本文最后的链接解决了问题。非常感谢原作者。

 

问题的原因是只装了PIL,但未成功安装LIBJPEG,下面是正确的安装脚本。

 

#!/bin/sh

# remove existing PIL
pip uninstall PIL

# install libjpeg
sudo apt-get install libjpeg62-dev

# make soft links
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/libz.so
#这里我的系统路径为/usr/lib/i386-linux-gnu/而不是 /usr/lib/x86_64-linux-gnu/


# download and install PIL
wget -c http://effbot.org/downloads/Imaging-1.1.7.tar.gz
tar xzvf Imaging-1.1.7.tar.gz
cd Imaging-1.1.7
python setup.py build_ext -i
python setup.py install

# if no errors is thrown up, jpeg_decoder was installed successfully
echo "from PIL import _imaging as core; core.jpeg_decoder"|python
   

 

参考原文:http://blog.shanbay.com/archives/842

 

 

 

 

 

你可能感兴趣的:(django)