我正在使用 Tornado,我想在模板中加载一些静态文件。现在我tornado.web.UIModule
用来加载它们。但是我得到了一些错误,说static_url()
没有定义。所以我查阅了文档,发现这个函数是tornado.web.RequestHandler
. 但是我怎样才能在下面的类中加载像这个函数这样的静态文件呢?
# _ * _ coding:utf-8 _ * _
import tornado.web
from tornado import template
class Header(tornado.web.UIModule):
"""docstring for Header"""
def render(self, hightlight = "index"):
return self.render_string("header.html", hightlight = hightlight)
def css_files(self):
css = [
static_url("css/smoothness/jquery-ui-1.8.20.custom.css"),
static_url("css/common.css"),
static_url("css/jquery.jqplot.min.css"),
static_url("css/blue/style.css"),
static_url("css/jquery.vector-map.css")
]
return css;
def javascript_files(self):
javascript = [
static_url("js/convert.color.js"),
static_url("js/jquery-1.7.2.min.js"),
static_url("js/jquery-ui-1.8.20.custom.min.js"),
static_url("js/common.js"),
static_url("js/jquery.jqplot.min.js"),
static_url("js/plugins/jqplot.highlighter.min.js"),
static_url("js/plugins/jqplot.cursor.min.js"),
static_url("js/plugins/jqplot.dateAxisRenderer.min.js"),
static_url("js/plugins/jqplot.canvasTextRenderer.min.js"),
static_url("js/plugins/jqplot.canvasAxisLabelRenderer.min.js"),
static_url("js/jquery.vector-map.js"),
static_url("js/china-cn.js"),
static_url("js/jquery.tablesorter.min.js"),
static_url("js/charts.js")
]
return javascript
def html_body(self):
return "<!--[if lt IE 9]><script src=\"{{ static_url(\"js/excanvas.js\") }}\"></script><![endif]-->"
def embedded_javascript(self):
return "<script>var current = null;</script>"