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



  • 相关阅读:
    百度ECharts数据绑定诀窍
    SQL操作Json数据
    c# 如何得到一个字符的ASCII码
    Sql数据库收缩 语句特别快
    Hive中 使用 Round() 的坑
    [转]Hive 数据类型
    [转] Hive函数大全
    使用Hive Rest API 连接HDInsight
    Hive动态分区 参数配置及语法
    Js的引用赋值与传值赋值
  • 原文地址:https://www.cnblogs.com/koushuige/p/8298676.html
Copyright © 2011-2022 走看看