Python的PIL图像库无效

时间:2015-04-16 22:25:34

标签: python pillow

尝试使用Pillow在我的Django管理员中保存图片时出现了一个奇怪的错误...

from PIL import _imaging as core
ImportError: cannot import name _imaging

File Models.py:

from django.db import models
from django.contrib.auth.models import User
from string import join
import os
from PIL.Image import core as _imaging
from PIL import Image as PImage
from my_site.settings import MEDIA_ROOT

class Image(models.Model):
    title       = models.CharField(max_length=60, blank=True, null=True)
    image       = models.FileField(upload_to="images/")
    created     = models.DateTimeField(auto_now_add=True)
    width       = models.IntegerField(blank=True, null=True)
    height      = models.IntegerField(blank=True, null=True)
    category    = models.ForeignKey(Category, blank=True, null=True)
    def save(self, *args, **kwargs):
        super(Image, self).save(*args, **kwargs)
        im = PImage.open(os.path.join(MEDIA_ROOT, self.image.name))
        self.width, self.height = im.size
        super(Image, self).save(*args, **kwargs)

文件Admin.py

class GenericImageAdmin(admin.ModelAdmin):
    list_display    = ["__unicode__", "title", "created", "thumbnail"]

    def save_model(self, request, obj, form, change):
        obj.user = request.user
        obj.save()

admin.site.register(GenericImage, GenericImageAdmin)

最奇怪的部分是我删除

时遇到同样的错误
from PIL.Image import core as _imaging

我使用的是Pillow,而不是旧的PIL。这笔交易是什么?

0 个答案:

没有答案