Sorl-Thumbnail static image in default
Asked Answered
F

2

8

I use Sorl-Thumbnail in my django-project. I have a situation, when I havent got 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" %} in default. I have an error:

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

How to fix it? Thanks.

Fitch answered 4/1, 2014 at 11:9 Comment(2)
have you solved the problem?Clutch
@Clutch yes, here is an answerFitch
C
10

I just found this alternative too:

{% 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 %}
Clutch answered 31/3, 2015 at 17:47 Comment(0)
F
1
{% if car.default_picture.image %}
thumbnail
{% else %}
{% static "img/no_image.png" %}
{% endif %}

It works for me

Fitch answered 31/3, 2015 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.