09 - 宏 | 继承 | 包含 | Flask
# 16.宏(macro),继承,包含 # 宏:模板中的函数,便于利用模板中重复内容|功能代码块的封装; # 模板中定义函数,给函数传参; # macr.html {% macro func(type='password',size='60') %} <input type="{{type}}" name="user" placeholder="user" size="{{size}}"> {% endmacro %} # 调用函数 {{func()}} # 任意文件中使用宏 # 导入宏文件 {% import 'macr.html' as m %} # 调用函数 {{m.func()}} # block,inculde(继承,包含)参考django中的使用; # 另外,include()无法包含表单这样的对象; # {% include 'xxx.html' ignore missing %} # 忽略包含文件不存在的错误; # 区别:继承,实现多个页面重复不变的区域;包含,将目标模板文件渲染出来; # 宏,类似函数,动态改变页面内容;优质内容筛选与推荐>>