tornado总结2-html模板使用1_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 08:49:16
Original
1066 people have browsed it

参考地址:

http://www.tornadoweb.org/en/stable/guide/templates.html?highlight=render


代码结构


page1.py和page1.html说明

page1.py

import tornado.webclass Page1Handler(tornado.web.RequestHandler): def get(self): argu1 = "参数1" argu2 = [1,2,3] return self.render('page1.html', argu1=argu1, argu2=argu2)
Copy after login

page1.html

  {{ argu1 }}
    {% for i in argu2 %}
  • {{ i }}
  • {% end %}
Copy after login

在处理get方法的时候, 使用render返回了一个html模板,并且添加了两个额外的参数argu1和argu2, tornado在返回html正文之前会对page1.html使用这些参数做相应的填充处理.

其中以 {{ }} 包围的是一个变量的值, 以 {% %} 包围的是执行语句,可以执行for和if 语句.但必须与 {% end %}成对出现.


实际运行效果


argu1作为title正确显示了出来,

argu2作为一个数组,也正确显示出了3个

  • .






  • source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!