Why can't I upload jpg files to my Django app via admin/?

后端 未结 9 1969
借酒劲吻你
借酒劲吻你 2020-12-16 14:16

I\'m trying to add images to my models in my Django app.

models.py

class ImageMain(models.Model):
  product = models.ForeignKey(Product)
  photo = mo         


        
9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 14:21

    Django is trying to import PIL from a folder called PIL, but PIL installs itself in a folder called e.g. PIL-1.1.7-py2.6-macosx-10.6-universal.egg, so the import fails - which Django (or PIL ?) seem to interpret as corrupt image.

    A simple symlink

    host:~ user$ cd /Library/Python/2.6/site-packages
    host:site-packages user$ ln -vis PIL-1.1.7-py2.6-macosx-10.6-universal.egg PIL
    create symbolic link `PIL' to `PIL-1.1.7-py2.6-macosx-10.6-universal.egg'
    

    has fixed this for me on a Mac OSX 10.6.x MBP. On Linux machines, the folder might instead be called dist-packages and be underneath /usr/lib/python/ or so, but the idea is the same.

    You can often find the folder where python modules are usually installed to as described here.

提交回复
热议问题