【发布时间】: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