Reputation: 673
I installed sorl-thumbnail to have a small thumbnail pictures in the gallery (in my django project - django-1.8). But the images are the same size as the original.
Code in template
{% 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 %}
My model
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)
Upvotes: 1
Views: 1015
Reputation: 45575
You should use the im
thumbnail instead of the original image
:
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
Upvotes: 1