【问题标题】:Setting dynamic crop on sorl.thumnail在 sorl.thumbnail 上设置动态裁剪
【发布时间】:2012-10-05 19:25:13
【问题描述】:

我在我的模型上添加了一个字段,用于指定缩略图的裁剪位置,但我似乎无法将其添加到模板标签中。

这是我现在的做法:

  {% if entry.main_image.crop_value == "center" %}
   {% thumbnail entry.main_image.image "350x100" crop="center" as im %}
        <a href="{{ entry.get_absolute_url }}"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""></a>
    {% endthumbnail %}
  {% elif entry.main_image.crop_value == "top" %}
   {% thumbnail entry.main_image.image "350x100" crop="top" as im %}
        <a href="{{ entry.get_absolute_url }}"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""></a>
    {% endthumbnail %}
  {% elif entry.main_image.crop_value == "bottom" %}
   {% thumbnail entry.main_image.image "350x100" crop="bottom" as im %}
        <a href="{{ entry.get_absolute_url }}"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""></a>
    {% endthumbnail %}
  {% endif %}

这不是最好的方法吗?

【问题讨论】:

  • {% thumbnail entry.main_image.image "350x100" crop=entry.main_image.crop_value as im %} 会发生什么?
  • 哈哈,我试过crop="entry.main_image.crop_value",但对""不起作用。谢谢!
  • 我会添加它作为答案

标签: django django-templates sorl-thumbnail


【解决方案1】:

可以在模板标签中使用变量:

{% thumbnail entry.main_image.image "350x100" crop=entry.main_image.crop_value as im %}

【讨论】:

    猜你喜欢
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-18
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多