#!/usr/bin/env python26
#-*- coding:utf8 -*- import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web import os.path from tornado.options import define,options
define("port",default=8001,help="run on this port",type=int) class TestHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html',header_text="Header goes here",footer_text="Footer goes here") def main():
tornado.options.parse_command_line() app=tornado.web.Application(
handlers=[(r"/",TestHandler)],
template_path=os.path.join(os.path.dirname(__file__),'templates'),
debug=True
) http_server=tornado.httpserver.HTTPServer(app) try:
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt,e:
print e if __name__ == "__main__":
main()

index.html

{% extends main.html %}
{% block header %} <h1>{{ header_text}} </h1>
{% end %} {%block body %}
<p> Hello from the child template!</p>
{% end %} {% block footer %}
<p> {{footer_text}} </p>
{% end %}

main.html

<html>
<body>
<header>
{% block header %}{%end%}
</header> <content>
{% block body %}{%end%}
</content> <footer>
{% block footer %}{%end%}
</footer>
</body>
</html>

tornado之子模板的更多相关文章

  1. JavaScript模板引擎artTemplate.js——引入子模板

    之前的例子都是单一结构的对象,如果遇到复杂对象结构,我们可以通过引入子模板来实现html的渲染. 依旧以之前的数据作为例子: <div id="content">< ...

  2. tornado 学习笔记9 Tornado web 框架---模板(template)功能分析

            Tornado模板系统是将模板编译成Python代码.         最基本的使用方式: t = template.Template("<html>{{ myv ...

  3. 在引用的laravel的@include子模板中传递参数

    调用传参: @include("message",['msg'=>'中国']) 在message子模板中调用msg的值: {{msg}}

  4. art-template辅助函数和子模板

    art-template 前端使用 用途:主要用来处理数据和优化性能,与其他的一些模块化处理数据的插件相比,art-template处理性能好 不废话,上代码 1.art-template基本语法使用 ...

  5. ZendFramework-2.4 源代码 - 关于MVC - View层 - 在模板内渲染子模板

    <?php // 方式一: // 1.在模板内直接编写如下内容即可 $viewModel = new ViewModel(); $viewModel->setTemplate('album ...

  6. tornado api 简单模板

    # 安装 pip insatll tornado # 主文件 web_server.py #!/usr/bin/env python # encoding: utf-8 import tornado. ...

  7. tornado 路由、模板语言、session

    一:tornado路由系统: 1.面向资源编程: 场景:当我们给别人提供api的时候,往往提供url.比如:电影票api: http://movie.jd.com/book_ticket:预订电影票. ...

  8. web框架--tornado框架之模板引擎继承

    使用模板的继承可以重复使用相同结构的模板, 可以大大减少代码量 入门实例 一.demo目录结构 注解: master.html为模板内容,被index.html,account.html引用 二.各文 ...

  9. web框架--tornado框架之模板引擎

    使用Tornado实现一个简陋的任务表功能demo来讲解tornado框架模板引擎 一.demo目录结构 二.具体文件内容 2.1.commons.css .body{ margin: 0; back ...

随机推荐

  1. HDU3336 Count the string

    居然一A了,说明对朴素的KMP还是有一定理解. 主要就是要知道next数组的作用,然后就可以计算每个i结尾的满足题意的串个数. #include<cstdio> #include<c ...

  2. Laravel框架使用查询构造器实现CURD

    一.什么是查询构造器? ①Laravel 查询构造器(query Builder)提供方便,流畅的接口,用来建立及执行数据库查找语法 ②使用PDO参数绑定,以保护应用程序免于SQL注入因此传入的参数不 ...

  3. C#无限分级实现,前端WEB页面接收,后台提供层级Json数据

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Te ...

  4. 使用olami sdk实现一个语音查询股票的iOS程序

    前言 在目前的软件应用中,输入方式还是以文字输入方式为主,但是语音输入的方式目前应用的越来越广泛.在这里介绍一个使用 Olami SDK 编写的一个使用语音输入查询股票的APP Olami SDK的介 ...

  5. chromium源码阅读--Browser进程初始化

    最近在研读chromium源码,经过一段懵懂期,查阅了官网和网上的技术文章,是时候自己总结一下了,首先IPC message loop开始吧,这是每个主线程必须有的一个IPC消息轮训主体,类似之前的q ...

  6. 张高兴的 Xamarin.Android 学习笔记:(二)“Hello World”

    完成环境配置后开始第一个简单项目.打开 Visual Studio 新建一个 Xamarin.Android 项目 "HelloAndroid".(GitHub:https://g ...

  7. Web前端性能优化——如何有效提升静态文件的加载速度

    WeTest 导读 此文总结了笔者在Web静态资源方面的一些优化经验. 一.如何优化 用户在访问网页时, 最直观的感受就是页面内容出来的速度,我们要做的优化工作, 也主要是为了这个目标.那么为了提高页 ...

  8. 博客迁移至 http://www.loveli.site

    对于博客园的Markdow 支持太过...,你懂的,  以后博客迁移至:http://www.loveli.site

  9. python基础6 迭代器 生成器

    可迭代的:内部含有__iter__方法的数据类型叫可迭代的,也叫迭代对象实现了迭代协议的对象 运用dir()方法来测试一个数据类型是不是可迭代的的. 迭代器协议是指:对象需要提供next方法,它要么返 ...

  10. 在你的网站实现qq登陆(php)

    这个qq的oauth2.1有个坑,坑了我半天,后来查了不少资料总算弄通了,现在把详细步骤记录下来. 步骤一.登陆http://connect.qq.com/     步骤二.创建应用.我创建的是wen ...