我的意见.py:
# obj is of Model subclass, image is its ImageField
timg = get_thumbnail(obj.image, "160x110", quality=50)
context['timg'] = timg
return render(request, '16_upload01.html', context)
我的模板:
{% thumbnail timg "100x100" crop="center" as timg %}
<img src="{{ timg.url }}" width="{{ timg.width }}" height="{{ timg.height }}">
{% empty %}
<p>No image</p>
{% endthumbnail %}
它永远显示“无图像”。但我可以timg
在控制台中看到:
(Pdb) timg
<sorl.thumbnail.images.ImageFile object at 0x10f83a450>
另外,在 settings.py 我设置THUMBNAIL_DEBUG = True
了,但看不到任何错误出现,为什么?
编辑
仍然没有显示缩略图
意见:
obj = Image.objects.filter(id=1)
timg = get_thumbnail(obj.image, "160x110", quality=50)
context['timg'] = timg
return render(request, '16_upload01.html', context)
模板:
<img src="{{ timg.url }}" width="{{ timg.width }}" height="{{ timg.height }}">