使用以下代码时:

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


为什么?而我该如何解决呢?

最佳答案

问题是您在链(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 %}

关于python - 无效的过滤器:“修订”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29474954/

10-12 16:03