自定義模板方法(類似django中的simple_tag) | Tornado
阿新 • • 發佈:2017-12-23
escape print eth pos pla html 文件 ngs mbed
# 自定義模板方法|相當於django中的simple_tag以及filter; # 1.uimethods.py def tag_one(self): print(self) return ‘tags‘ # 2.uimodules.py from tornado.web import UIModule from tornado import escape class Custom(UIModule): def embedded_css(self): # 頁面添加css樣式 return‘body{color:blue;}‘ def css_files(self): # 前端引入css文件 return ‘set.css‘ def render(self, *args, **kwargs): print(args, kwargs) return ‘<h1>miaokela</h1>‘ # return escape.xhtml_escape(‘<h1>miaokela</h1>‘)# 5.tornado_test.py # uimodules除了顯示頁面內容,還可以在後臺自定制JS與CSS; import uimethods as mt import uimodules as md # 8.配置靜態文件 settings = { # 靜態文件目錄 ‘static_path‘: ‘static‘, # url請求時前綴,如果不加,默認是項目根目錄下絕對路徑; ‘static_url_prefix‘: ‘/test/‘, # 模板文件路徑 ‘template_path‘: ‘templates‘, # 自定義模板方法 ‘uimethods‘: mt, ‘uimodules‘: md, } # 4.login.html <h1>登錄:{{ tag_one }}{% module Custom() %}</h1>
自定義模板方法(類似django中的simple_tag) | Tornado