使用以下代码时:
{% with ""|add:revision.width|add:"x"|revision.height as dimensions %}
{% thumbnail revision.image dimensions as thumb %}
{% endwith %}
我收到以下错误:
Django Version: 1.6.11
Exception Type: TemplateSyntaxError
Exception Value:
Invalid filter: 'revision'
Exception Location: /usr/local/lib/python2.7/site-packages/django/template/base.py in find_filter, line 366
Python Executable: /usr/local/bin/python
Python Version: 2.7.9
为什么呢?我该怎么做才能解决它?
答案 0 :(得分:2)
问题是链中最后一次应用的过滤器(revision.height
)。
替换:
{% with ""|add:revision.width|add:"x"|revision.height as dimensions %}
使用:
{% with ""|add:revision.width|add:"x"|add:revision.height as dimensions %}
您还可以将变量分配给revision.width
和revision.height
:
{% with width=revision.width height=revision.height %}
{% with ""|add:width|add:"x"|add:height as dimensions %}
...
{% endwith %}
{% endwith %}