-
自定义函数
def house_title_join(titles): return "+".join(titles) class IndexHandler(RequestHandler): def get(self): house_list = [ { "price": 398, "titles": ["宽窄巷⼦", "160平⼤空间", "⽂化保护区双地铁"], "score": 5, "comments": 6, "position": "北京市丰台区六⾥桥地铁" }, { "price": 398, "titles": ["宽窄巷⼦", "160平⼤空间", "⽂化保护区双地铁"], "score": 5, "comments": 6, "position": "北京市丰台区六⾥桥地铁" 现在,我们对模板index.html进⾏抽象,抽离出⽗模板base.html如下: }] self.render("index.html", houses=house_list, title_join = house_title_join)
<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>
Tornadao—模板语法(自定义函数)
猜你喜欢
转载自blog.csdn.net/piduocheng0577/article/details/105061145
今日推荐
周排行