【问题标题】:Sorl-Thumbnail static image in defaultSorl-Thumbnail 默认为静态图片
【发布时间】:2014-01-22 02:22:06
【问题描述】:

我在我的 django 项目中使用 Sorl-Thumbnail。我有一种情况,当我没有图像时,我需要显示no_image.png。 此代码有效:

{% 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 %}

但我想默认使用{% static "img/no_image.png" %}。我有一个错误:

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

如何解决?谢谢。

【问题讨论】:

  • 问题解决了吗?
  • @MatheusJardimB 是的,这是一个答案

标签: django sorl-thumbnail


【解决方案1】:
{% if car.default_picture.image %}
thumbnail
{% else %}
{% static "img/no_image.png" %}
{% endif %}

对我有用

【讨论】:

    【解决方案2】:

    我也发现了这个替代方案:

    {% 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 %}
    

    【讨论】:

      猜你喜欢
      • 2010-12-03
      • 1970-01-01
      • 2017-08-09
      • 2019-06-10
      • 2014-04-30
      • 2018-01-06
      • 2012-03-01
      • 2012-09-18
      • 1970-01-01
      相关资源
      最近更新 更多