【问题标题】:If statement using templatetag [closed]If语句使用模板标签[关闭]
【发布时间】:2011-11-28 20:40:16
【问题描述】:

我将如何在 django 中执行以下操作:

{% if value|truncatewords > 10 %} print this {% endif %}

谢谢。

【问题讨论】:

  • 你想做什么?为什么要将字符串与整数进行比较?

标签: django django-templates


【解决方案1】:

我打赌你想计算字符串中的单词。试试这个:

{% if value|wordcount > 10 %} print this {% endif %}

【讨论】:

    【解决方案2】:

    这是对truncatewords 过滤器的错误使用。您必须指定要截断的字数:

    {{ value|truncatewords:10 }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多