尝试使用Pillow在我的Django管理员中保存图片时出现了一个奇怪的错误...
from PIL import _imaging as core
ImportError: cannot import name _imaging
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)
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