为什么我无法通过admin /?将jpg文件上传到我的Django应用程序? [英] Why can't I upload jpg files to my Django app via admin/?
问题描述
我正在尝试在我的Django应用程序中添加图像到我的模型。
models.py
class ImageMain(models.Model):
product = models.ForeignKey(Product)
photo = models.ImageField(upload_to ='products')
在开发模式下,每次我尝试通过Django管理员上传图像时,我一直在:
上传有效的图片。您上传的文件不是图像或
a损坏的图像。
我通过fink安装了libjpeg,然后安装了PIL 1.1 .6 on ox X 10.5.7
从PIL导入图像
/ pre>
file = open('/ Users / Bryan / work / review_app / media / lcdtvs / samsung_UN46B6000_front.jpg','r')
trial_image = Image.open(file)
trial_image.verify()
似乎jpg基于该会话有效。但是,它不加载。
我尝试过其他jpg,他们也不工作。
可能会出错?
我能够成功上传一个png文件。
解决方案在PIL已经编译/安装之后,是否安装了libjpeg系统?也许它找不到解码器?
这里有一组我在使用libjpeg和pIL在MacOS上播放的指令(看到最后,看起来像你可能需要明确设置解码器的目录):
I'm trying to add images to my models in my Django app.
models.py
class ImageMain(models.Model): product = models.ForeignKey(Product) photo = models.ImageField(upload_to='products')
In development mode, every time I try to upload the image via Django admin, I keep getting:
Upload a valid image. The file you uploaded was either not an image or a corrupted image.
I installed libjpeg via fink and then installed PIL 1.1.6 on ox X 10.5.7
from PIL import Image file = open('/Users/Bryan/work/review_app/media/lcdtvs/samsung_UN46B6000_front.jpg', 'r') trial_image = Image.open(file) trial_image.verify()
It seems that the jpg is valid based on that session. However, it does not load. I have tried other jpgs, they don't work either.
What could be going wrong?
I was able to successfully upload a png file.
解决方案Did you install libjpeg after PIL was already compiled/installed on the system? Maybe it can't find the decoder properly?
Here's one set of instructions I found on getting libjpeg and PIL playing nicely on MacOS (see towards the end; looks like you may need to explicitly set the dir of the decoder):
这篇关于为什么我无法通过admin /?将jpg文件上传到我的Django应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!