【发布时间】:2014-03-09 19:39:37
【问题描述】:
在 Jinja2 中,宏和包含似乎做了几乎相同的事情。
例如
{% macro input(name, value='', type='text') -%}
<input type="{{ type }}" value="{{ value|e }}" name="{{ name }}">
{%- endmacro %}
{{ input('password', type='password') }}
-- versus --
{% include 'input.html' %}
input.html file>
<input type="{{ type }}" value="{{ value|e }}" name="{{ name }}">
为了阐明它们的用途:
- 是否有一个时间可以工作,而另一个不可以?
- 如果两者都能奏效,我们应该在什么时候选择一个而不是另一个?
【问题讨论】: