过滤器无效:'修订版'

时间:2015-04-06 16:09:28

标签: python django

使用以下代码时:

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

为什么呢?我该怎么做才能解决它?

1 个答案:

答案 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.widthrevision.height

{% with width=revision.width height=revision.height %}
    {% with ""|add:width|add:"x"|add:height as dimensions %}
        ...
    {% endwith %}
{% endwith %}