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.
在我的模板中,我使用了一个名为 myTag 的自定义 simple_tag 并采用了两个 args :
{% myTag arg1 arg2 %}
它返回给我一个字符串。
我想在返回时使用 truncatewords 内置模板标签过滤器,但我找不到正确的语法...
总而言之,我想要类似的东西:
<h1>{% myTag arg1 arg2 %}|truncatewords:2</h1>
也许您想改用分配标签。
那么你可以这样做:
{% myTag arg1 arg2 as answer %} {{ answer|truncatewords:2 }}