gpt4 book ai didi

python - 在tornado中,如何在没有tornado.web.RequestHandler的类中使用static_url()?

转载 作者:太空宇宙 更新时间:2023-11-03 19:18:07 24 4
gpt4 key购买 nike

我正在使用 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>"

最佳答案

正如您已经提到的,static_urltornado.web.RequestHandler 的一种方法,但您将其作为全局函数调用。

改变

static_url(...)

self.handler.static_url(...)

关于python - 在tornado中,如何在没有tornado.web.RequestHandler的类中使用static_url()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10696033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com