Default Sorl-Thumbnail Static Image

I am using Sorl-Thumbnail in my django project. I have a situation where I do not have an image and I need to show no_image.png . This code works:

 {% thumbnail car.default_picture.image|default:"http://example.com/img/no_image.png" "240x180" crop="center" as im %} <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"> {% endthumbnail %} 

But I want to use {% static "img/no_image.png" %} by default. I have an error:

 TemplateSyntaxError: Syntax error. Expected: ``thumbnail source geometry [key1=val1 key2=val2...] as var` 

How to fix it? Thanks.

+7
django sorl-thumbnail
source share
2 answers

I also found this alternative:

 {% thumbnail product.logo "200x200" crop="center" as im %} <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"> {% empty %} <img src="{% static 'images/default.gif' %}" width="200" height="200"> {% endthumbnail %} 
+9
source share
 {% if car.default_picture.image %} thumbnail {% else %} {% static "img/no_image.png" %} {% endif %} 

It works for me

+1
source share

All Articles