How to use Pillow with Django

前端 未结 4 1449
借酒劲吻你
借酒劲吻你 2021-02-18 16:44

I installed Pillow and now want to use it on my Django site to allow uploading of images of through my admin page. See previous question.

What changes do I need to make

相关标签:
4条回答
  • 2021-02-18 17:26

    You shouldn't have to make any changes in your settings.py or otherwise to use Pillow instead of PIL. Its a drop-in replacement, and simply has to be available on your PYTHONPATH.

    0 讨论(0)
  • 2021-02-18 17:40

    First, install pillow (having virtualenv activated preferably) with:

    pip install pillow
    

    You should import it in Django project:

    from PIL import Image
    

    After that you don't need to change settings or anything else. All the modules should work.

    0 讨论(0)
  • 2021-02-18 17:41

    The problem is that imports now work slightly differently with Pillow vs PIL. The differences are described here: http://pillow.readthedocs.org/en/latest/porting-pil-to-pillow.html

    Django has also now been changed to prefer Pillow over PIL, via this ticket (https://code.djangoproject.com/ticket/19934)

    This commit is present in the new Django 1.6a1 release, so the new behaviour will be present in the Django 1.6 release. For now, however, it appears that you can use a new library (initially released May 20, 2013) called Pillow-PIL which will provide a compatibility layer. This can be easily installed with pip via: pip install --pre Pillow-PIL

    0 讨论(0)
  • 2021-02-18 17:46

    In a Python module that makes a drawing I simply put the following.

    import PIL.Image as Image
    

    and likewise for ImageDraw and ImageFont. Those were the only changes that were necessary after a routine PIP installation.

    0 讨论(0)
提交回复
热议问题