- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 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_url
是 tornado.web.RequestHandler
的一种方法,但您将其作为全局函数调用。
改变
static_url(...)
至
self.handler.static_url(...)
关于python - 在tornado中,如何在没有tornado.web.RequestHandler的类中使用static_url()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10696033/
一个可怜的 Django 初学者在访问某些 View 上的静态文件(css、js)时遇到了阻塞问题。主要是,在主页上,这些静态文件是完全可以访问的,但在不同的页面上,则不能,并且布局完全损坏。 这是我
我正在尝试使用 Apache+mod_wsgi 将我的 Django 应用程序部署到生产环境中,但遇到了静态文件的问题。由于某种原因,我在生产中的模板无法识别 {{ STATIC_URL }} 。在开
我正在尝试在 Django 中使用 Twitter Bootstrap。我大部分时间都在使用它。我有一个正确链接 CSS 的 profile.html 模板,但我有一个没有在 STATIC_URL 前
Django 版本是 1.4。我已经阅读了官方文档,并用谷歌搜索了我的问题。 首先我是按照官方文档Managing static files在 settings.py 中添加: TEMPLATE_CO
http://docs.djangoproject.com/en/dev/howto/static-files/ 这表明我可以使用 STATIC_URL在我的模板中从 settings.py 中获取值
是的,我希望它像 Flask 框架一样工作 - 我可以像这样设置参数: static_folder=os.getcwd()+"/static/", static_url_path="" 并且 ./st
我正在尝试升级 django-summernote到我的 django 1.9 项目中的版本 0.8.5,但是使用给定的设置,我收到此错误: File "my_project/settings/ba
如果我只定义一个,页面显示时没有任何 CSS/JS。如果我定义两者,页面加载正常。这是为什么?我认为 STATICFILES_DIRS 是无关紧要的? 这里有一个答案,但它没有回答为什么我需要两者。它
请考虑我的 django 项目下面给出的 seetings.py 文件 # Django settings for sadhana project. DEBUG = True TEMPLATE_DEB
我在 http://example.com 上有一个公司 wordpress 博客,在 http://example.com/web 上成功部署了 Django 应用程序。 我的应用程序是一个简单的应
我是 Python 和 Tornado 网络框架的初学者。在研究《Introduction to Tornado》一书中的模板部分时,有一行让我很困惑: 当没有库导入到命名空间时,应用程序如何知道在
我有一个模板,base.html,它在其他几个模板中用于各种 View 。这些模板中的每一个都以适当的 {% extends "base.html"%} 开头。在基本模板中,我想这样指定一个静态样式表
我在使用 {{ STATIC_URL }} 在模板中添加 CSS 时遇到了一些麻烦。该标签在链接标记内不起作用,但在其他任何地方都起作用。 这个: {{ STATIC_URL }} 正确翻译成 /st
我的基本文件中有以下代码行: document.write(''); 最近我从 Django 1.6 升级到 1.11,并且正在从使用 STATIC_URL 切换到使用 {% static %}。但是
我的问题是我在 java 脚本代码中使用 Django STATIC_URL 。我的代码在我的开发环境中工作,但是当我将其上传到 pythonanywhere.com 时,它无法工作。我检查了我的代码
在我的网站中,我集成了一个样式表和一个 javascript 文件。我按如下方式加载它: javascript 有效,但样式表无效。我也这样试过: 当我这样做时,样式表将加载,但是当我从未连接
我有一个 django(1.6.5) 项目,我正在使用 django-configurations(0.8)包,我正在尝试通过以下方式使用环境变量在 settings.py 文件中设置 STATIC_
在 Pyramid 应用程序中,我定义了一个用于提供 css/js 文件的静态 View 和另一个用于提供上传文件等其他数据的静态 View : config.add_static_view('sta
所以我现在正在尝试在服务器上运行 Django 的多个实例,一个在 /dev/ 下,一个在 /test/ 下,等等。 网络服务器正在设置正确的 SCRIPT_NAME 设置,我可以正常提供页面、模板和
当我在 urls.py 中添加 STATIC_URL 时: urlpatterns = [...]+static(settings.STATIC_URL) 但我得到了 ^static\/(?P.*)$
我是一名优秀的程序员,十分优秀!