【发布时间】:2009-10-19 20:54:28
【问题描述】:
我有一些静态文本需要显示在模板中的 2 个位置。
例如:
<div>
{% if something %}
This is a static text
{% else %}
Something else happened
{% endif %}
</div>
... more html
<span>
{% if something %}
This is a static text
{% else %}
Something else happend
{% endif %}
</span>
- 我可以通过在模板文件中的 2 个不同位置复制上述文本来完成上述操作(如上所示)。
- 我还可以创建一个模型来存储文本(这是 DRY,但需要调用数据库来完成一个简单的任务)
- 我正在考虑使用
include template,但这可能不是实现目标的最佳方式。
最好的方法是什么?
【问题讨论】:
-
使用
include两次看起来不错。