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



  • 相关阅读:
    iOS 多线程/GCD
    iOS推送通知的实现步骤
    Swift中文教程-学习
    设计模式——观察者模式
    SSM学习
    Servlet 学习
    java基础
    DOM中节点
    会议管理系统设计
    springboot与thymeleaf 整合
  • 原文地址:https://www.cnblogs.com/koushuige/p/8298676.html
Copyright © 2011-2022 走看看