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.
我想检测 Jinja2 模板块内容是否为空。像这样的东西:
{% block foo %}{% endblock foo %}{% if foo %} - {% endif %}Blah Blah Blah
我想要的是块定义本身之外的条件文本。在人为设计的示例中,当且仅当该块已被覆盖且不为空时,我希望能够在该块- 之后插入一个条件字符串。
-
这可能吗?
只需调用块:
{% if self.foo() %} - {% endif %}