模板继承示例
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>{% block title %} {% endblock %}</title> 6 <link rel="stylesheet" href="/static/commons.css" /> 7 <style> 8 .pg-header{ 9 height: 50px; 10 background-color: seashell; 11 color: green; 12 } 13 </style> 14 {% block css %} {% endblock %} 15 </head> 16 <body> 17 <div class="pg-header">小男孩管理</div> 18 <div> 19 <a>asdf</a> 20 <a id="">asdf</a> 21 <a>asdf</a> 22 <a>asdf</a> 23 <a>asdf</a> 24 </div> 25 <iframe src="/"></iframe> 26 </body> 27 </html>
继承
1 {% extends ‘master.html‘ %} #继承master.html,只能继承一个模版 2 3 {% block title %}用户管理{% endblock %} 4 5 {% block content %} 6 <h1>用户管理</h1> 7 <ul> 8 {% for i in u %} 9 <li>{{ i }}</li> 10 {% endfor %} 11 </ul> 12 13 {% for i in u %} 14 {% include ‘tag.html‘ %} #include导入一个模板,可导入多个 15 {% endfor %} 16 17 {% endblock %} 18 19 {% block css %} 20 <style> 21 body{ 22 background-color: red; 23 } 24 </style> 25 {% endblock %} 26 27 {% block js %} 28 <script></script> 29 {% endblock %}
时间: 2024-09-30 04:38:17