出于某种原因,一旦我尝试将 ImageKit 应用到模型上以创建 ImageField 的缩略图,就会出现错误。我正在使用适用于 Django 的 ImageKit 库,您可以在此处找到
我的代码如下:
from django.db import models
from PIL import Image
import os
from django.contrib import admin
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill
# Create your models here.
class ResidentialReference(models.Model):
image = models.ImageField(upload_to='images', blank="true",null="true")
thumbnail = ImageSpecField(source='image',
processors=[ResizeToFill(100,50)],
format='JPEG',
options={'quality':60})
title = models.CharField(max_length = 1000, default = 'Title here...' )
postcode = models.TextField(max_length = 1000, default='Postcode here...')
description = models.TextField(max_length = 12000, default = 'Technical Description here...')
equipment = models.TextField(max_length = 1000, default = 'Equipment here...')
output = models.TextField(max_length = 1000, default = 'Rated Output here...')
partnership = models.TextField(max_length = 12000, default = 'Viessmann partnership details here...')
def __unicode__(self):
return self.title
def create_thumb(self):
residentialReference = ResidentialReference.objects.all()[0]
print residentialReference.thumbnail.url
print residentialReference.thumbnail.width