-
块
我们可以使⽤块来复⽤模板,块语法如下: {% block block_name %} {% end %}
{# 对模板index.html进⾏抽象,抽离出⽗模板base.html base.html #} <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initialscale=1, maximum-scale=1, user-scalable=no"> {% block page_title %}{% end %} <link href=" {{static_url('plugins/bootstrap/css/bootstrap.min.css')}}" rel="stylesheet"> <link href="{{static_url('plugins/font-awesome/css/fontawesome.min.css')}}" rel="stylesheet"> <link href="{{static_url('css/reset.css')}}" rel="stylesheet"> <link href="{{static_url('css/main.css')}}" rel="stylesheet"> {% block css_files %}{% end %} </head> <body> <div class="container"> <div class="top-bar"> {% block header %}{% end %} </div> {% block body %}{% end %} <div class="footer"> {% block footer %}{% end %} </div> </div> <script src="{{static_url('js/jquery.min.js')}}"></script> <script src=" {{static_url('plugins/bootstrap/js/bootstrap.min.js')}}"></script> {% block js_files %}{% end %} </body> </html>
{# ⼦模板index.html使⽤extends来使⽤⽗模板base.html #} {% extends "base.html" %} {% block page_title %} <title>爱家-房源</title> {% end %} {% block css_files %} <link href="{{static_url('css/index.css')}}" rel="stylesheet"> {% end %} {% block js_files %} <script src="{{static_url('js/index.js')}}"></script> {% end %} {% block header %} <div class="nav-bar"> <h3 class="page-title">房 源</h3> </div> {% end %} {% block body %} <ul class="house-list"> {% if len(houses) > 0 %} {% for house in houses %} <li class="house-item"> <a href=""><img src="/static/images/home01.jpg"></a> <div class="house-desc"> <div class="landlord-pic"><img src="/static/images/landlord01.jpg"></div> <div class="house-price">¥<span>{{house["price"]}} </span>/晚</div> <div class="house-intro"> <span class="house-title"> {{title_join(house["titles"])}}</span> <em>整套出租 - {{house["score"]}} 分/{{house["comments"]}}点评 - {{house["position"]}}</em> </div> </div> </li> {% end %} {% else %} 对不起,暂时没有房源。 {% end %} </ul> {% end %} {% block footer %} <p><span><i class="fa fa-copyright"></i></span>爱家租房 享受家的温馨</p> {% end %}
Tornadao—模板语法(块)
猜你喜欢
转载自blog.csdn.net/piduocheng0577/article/details/105069175
今日推荐
周排行