zoukankan      html  css  js  c++  java
  • tornado 作业 自定义模板 UIMethod以UIModule

    自定义uimodule

    s3.py

    import tornado.ioloop
    import tornado.web
    import UIMethod as mt
    
    class MainHandler(tornado.web.RequestHandler):
        def get(self):
            self.render("s3.html")
        def post(self, *args, **kwargs):
            self.render('s3.html')
    settings={
        'template_path':'tpl',
        'static_path': 'static',
        'ui_methods': mt,
    }
    
    application = tornado.web.Application([
        (r"/index", MainHandler),
    ],**settings)
    
    if __name__ == "__main__":
        application.listen(8888)
        tornado.ioloop.IOLoop.instance().start()

    s3.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <h3>{{func()}}</h3>
    </body>
    </html>
    UIMethod.py
    def func(self):
        return '123'
     

     自定义UIModule

    s3.py

    import tornado.ioloop
    import tornado.web
    import UIModule as md
    class MainHandler(tornado.web.RequestHandler):
        def get(self):
            self.render("s3.html")
        def post(self, *args, **kwargs):
            self.render('s3.html')
    settings={
        'template_path':'tpl',
        'static_path': 'static',
        'ui_modules': md,
    }
    
    application = tornado.web.Application([
        (r"/index", MainHandler),
    ],**settings)
    
    if __name__ == "__main__":
        application.listen(8888)
        tornado.ioloop.IOLoop.instance().start()

    s3.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <h3>{% module custom()%}</h3>
    </body>
    </html>

    UIModule.py

    from tornado.web import UIModule
    from tornado import escape
    
    class custom(UIModule):
    
        def render(self, *args, **kwargs):
            return 123



  • 相关阅读:
    js简单排序
    js希尔排序
    js直接插入排序
    大数运算
    IOC和AOP的理解 (持续更新)
    频发事件的缓存技巧
    执行上下文深入解析(Execution Context)
    二分
    HDU 3790 最短路径问题 (双重权值)
    浅谈Targan算法
  • 原文地址:https://www.cnblogs.com/koushuige/p/8298676.html
Copyright © 2011-2022 走看看