爲什麼thumbnail
模板標籤不適用於下面詳述的設置?Django solr-thumbnail redis配置
Django的項目以這種方式配置(相關文件的摘錄):
settings.py(摘錄)
INSTALLED_APPS = (
..
'sorl.thumbnail',
..
)
..
# solr-thumbnail related settings
THUMBNAIL_FORMAT = 'PNG'
THUMBNAIL_KVSTORE = 'sorl.thumbnail.kvstores.redis_kvstore.KVStore'
THUMBNAIL_REDIS_HOST = 'localhost' # default
THUMBNAIL_REDIS_PORT = '6379' # default
models.py
from django.db import models
from sorl.thumbnail import ImageField
class UserProfile(models.Model):
email = models.EmailField()
profile_pic = ImageField(upload_to='user_profile_imgs')
views.py(提取物)
form = NewUserForm(request.POST, request.FILES)
if form.is_valid():
user_inst = UserProfile(
email=form.cleaned_data['email'],
profile_pic=request.FILES['image']
)
user_inst.save()
return ..
HTML模板(摘錄)
<p>Actual image</p> <!-- THIS WORKS -->
<img src="{{ user.profile_pic.url }}" alt="user profile pic">
<p>Cropped image</p> <!-- THIS DOES NOT WORK -->
{% thumbnail user.profile_pic "100x100" crop="smart" as im %}
<img src="{{ im.url }}" alt="user profile pic 100 by 100">
{% endthumbnail %}
裁剪的圖像無法正常工作;根據sorl-django workflow,如果沒有找到我配置的Redis緩存中的密鑰,則應該創建新請求的映像。實際上,在檢查時,redis緩存根本沒有任何項目:
redis 127.0.0.1:6379> KEYS *
(empty list or set)
因此,sorl-thumbnail甚至沒有在redis上創建密鑰。我無法弄清楚問題所在,因爲我什麼都不例外。我有感覺我錯過了某個步驟。 (通過蛋黃)
相關的Python包版本:
Django - 1.5.1 - active
Pillow - 2.0.0 - active
redis - 2.7.6 - active
sorl-thumbnail - 11.12 - active