• 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



  • 相关阅读:
    c# gdi设置画刷透明
    char,varchar,nvarchar,text区别与联系
    banner无缝轮播【小封装】
    div中的内容垂直居中的五种方法
    jQuery hover() 方法
    年过三十,我为什么要学习ios 与安卓App 移动端技术
    CentOS 中用 Split 命令分割文件的方法
    centos E440 安装无线网卡
    CentOS7修改默认运行级别
    iwconfig: command not found 解决方案
  • 原文地址:https://www.cnblogs.com/koushuige/p/8298676.html
Copyright © 2020-2023  润新知