zoukankan      html  css  js  c++  java
  • tornado之子模板

    #!/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>
  • 相关阅读:
    Python基础笔记(五)
    Python基础笔记(四)
    Python基础笔记(三)
    Python基础笔记(二)
    Python基础笔记(一)
    分页存储过程
    MD Test
    vue路由的配置技巧
    Echarts的使用与配置项
    js中call,apply,bind之间的区别
  • 原文地址:https://www.cnblogs.com/gsblog/p/3327173.html
Copyright © 2011-2022 走看看