我安装了sorl-缩略图,以便在图库中有一个小缩略图(在我的django项目-django-1.8中)。但这些图像与原始图像大小相同。
模板中的代码
{% for image in gallery %}
{{ image.title }} <br>
{% thumbnail image "100x100" as im %}
<img src="{{ image.paint.url }}" width="{{ image.width }}" height="{{ image.height }}"><br>
{% endthumbnail %}
{{ image.status }}<br>
{{ image.price }}<br>
{% endfor %}我的模型
class Paint(models.Model):
title = models.CharField(max_length=200)
gallery = models.ForeignKey(Gallery)
paint = ImageField(upload_to='paint/%Y/%m/%d')
price = models.CharField(max_length=50, blank=True, null=True)
status = models.CharField(choices=STATUS_PAINT, default=AVAILABLE, max_length=50)
class Meta:
verbose_name = "Picture"
verbose_name_plural = "Images"
def __unicode__(self):
return "{}".format(self.title)发布于 2015-04-21 15:02:16
您应该使用im缩略图而不是原始的image
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">https://stackoverflow.com/questions/29775959
复制相似问题