在sorl.thumbnail
上激活调试后,我收到此错误
Error importing module thumbnails.models: "No module named thumbnails.models"
向下看第38行的错误回调,我发现了这个:
36 {% for article in object_list %}
37 <img src="{{article.photo.url}}" width="100px" >
38 {% thumbnail article.photo "100x100" as im %}**
39 <img src="{{ im.url }}" >
40 {% empty %}
41 <p>Thumbnail : No image</p>
我使用主数据库作为缓存,具有以下设置:
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'app',
'USER': 'root',
'PASSWORD': 'root',
'PORT': '',
}
}
.
.
.
.
CACHE_BACKEND = 'db://thumbnail_cache'
THUMBNAIL_QUALITY = 90
THUMBNAIL_PREFIX = 'images/'
THUMBNAIL_BACKEND = 'thumbnails.models.SEOThumbnailBackend'
THUMBNAIL_DEBUG = True
THUMBNAIL_KVSTORE = 'sorl.thumbnail.kvstores.cached_db_kvstore.KVStore'
THUMBNAIL_CACHE_TIMEOUT = 3600 * 24 * 365
THUMBNAIL_ENGINE = 'sorl.thumbnail.engines.pil_engine.Engine'
models.py
from sorl.thumbnail import ImageField
class Foto(models.Model):
user = models.ForeignKey('app.User', blank=True, null=False)
date = models.DateTimeField(auto_now_add=True)
photo = ImageField(upload_to='%Y/%m/%d', null=True, blank=True)