include标签
1.这个标签相当与是直接将指定的模板中的代码复制粘贴到当前位置
2.include
标签,如果想要使用父模板中的变量,直接用就可以了,不需要使用with context
.
3.include
的路径,也是跟import
一样,直接从templates
根目录下去找,不要以相对路径去找
with
语句
with
语句定义的变量,只能在with
语句块中的使用,超过了这个代码块,就不能再使用了。
{% with classroom = 'hello'%}
<p>班级:{{ classroom}}<P>
{% endwith %}
with
语句也不一定要跟一个变量,可定义一个空的with
语句,以后在with
块中通过set
定义的变量,就只能在这个with
块中使用了:
{% with %}
{% set classroom = 'hello'%}
<p>班级:{{ classroom}}<P>
{% endwith %}
set
语句
在模板中,可以使用set
语句来定义变量。
{% set classroom = 'hello'%}
<p>班级:{{ classroom}}<P>
一旦定义了这个变量,那么在后面的代码中,都可以使用这个变量,就类似于Python的变量定义是一样的。