一.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

相关文章:

  • 2021-10-12
  • 2021-09-28
  • 2021-11-03
  • 2021-08-09
  • 2021-07-20
  • 2021-11-01
  • 2021-10-27
  • 2021-10-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2021-09-06
相关资源
相似解决方案