Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
代码:
{% firstof m.caption m.altcaption|slice:":37" %}
我想选择这两个变量中的第一个,然后滑动到 37 个字符。有任何想法吗?
在 Django 1.9+ 中,您可以将firstof标记的结果分配给变量。
firstof
{% firstof m.caption m.altcaption as caption %} {{ caption|slice:":37"}}
在早期版本中,您可以过滤两个参数
{% firstof m.caption|slice:":37" m.altcaption|slice:":37" %}