一.UIMOTHODS:

1.在项目目录创建uimothods.py文件(名称可以任意)
内容:
def test2(self):
return ('hello uimothods')

2.tornado项目文件中导入并注册:
#导入
from utils import uimothods as mt
#注册
settings = {

'ui_modules': mt
}
3.在html中调用uimethod
{{test2()}}

二.UImodules:
1.在项目目录创建uimodules.py文件(名称可以任意)
from tornado.web import UIModule
from tornado import escape
class test(UIModule):
    def render(self, *args, **kwargs):
        return ('<h1>UIMODULES</h1>') #返回html文件,不转义
        #return escape.xhtml_escape('<h1>UIMODULES</h1>') #对返回内容进行转义
    def embedded_javascript(self):#在html中插入js
        return 'a.js'
    def embedded_css(self):#在html中插入css
        return 'a.css'
View Code

相关文章: