http://www.tornadoweb.org/en/stable/guide/templates.html?highlight=render#ui-modules
osc的所有页面顶部都有这个导航条, 我们可以使用tornado的UI modules来实现导航条,实现代码的复用.
增加了一个my_uimodules.py,里面包含了供tornado模板使用的uimodules,增加了一个header.html里面是导航条的html代码,增加了一个page2.py,返回简单的html页面page2.html.
访问路径 "/"时的效果
点击导航链接 "页面1"的效果
点击导航链接 "页面2"的效果
my_uimodules.py
import tornado.webclass HeaderBar(tornado.web.UIModule): def render(self, location): return self.render_string("header.html", location=location)class HeaderBar2(tornado.web.UIModule): def render(self, location): return self.render_string("header.html", location=location)
所有的模板驱动都继承自 tornado.web.UIModule , 然后调用render_string调用指定的模板和参数. 你可以在此处写一个顶部导航栏再写个侧边导航栏. 我只在这里写了一个顶部导航模板驱动. 它接受一个参数location, 我把它作为导航栏最右侧的页面说明. 本模板驱动返回的是header.html,并把location传给了它.
header.html
主页 页面1 页面2 你现在处于页面 {{ location }}
查看更多关于tornado总结4-html模板使用2_html/css_WEB-ITnose的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did112092