【问题标题】:Create .html file with tornado with link to static css创建带有指向静态 css 链接的龙卷风的 .html 文件
【发布时间】:2018-05-25 08:24:40
【问题描述】:

使用 Tornado,我想创建一个 html 文件并将其保存以供以后重复使用。在 html 中,我想在我的静态文件中引用引导 css。

我的简化 html 看起来像这样,跟在 Tornado/Python self.render("example.html") ignores CSS 之后

<html>

<head>
    <link rel="stylesheet" type="text/css" href="{{static_url('app/content/bootstrap.css')}}" />
</head>

<body>
{{name}}
</body>
</html>

我的简化 .py 看起来像这样:

import tornado.template
loader=tornado.template.Loader(r"C:\templateDirectory")
output_from_parsed_template= loader.load("template.html").generate(name="John")

# to save the results
file = open(r"C:\templateDirectory\result.html","w")
file.write(output_from_parsed_template)
file.close()

但是,我得到消息:

NameError: name 'static_url' is not defined

【问题讨论】:

    标签: python html css twitter-bootstrap tornado


    【解决方案1】:

    Tornado 模板中使用的许多预定义名称来自RequestHandler,而不是模板系统本身(因为它们需要应用程序级别的配置)。要按原样使用static_url,您将需要整个服务堆栈,而不仅仅是一个 Loader 和 Template.generate(或者您可以深入研究代码并重建它在做什么)。

    【讨论】:

    • 感谢本·达内尔。你能指出一个例子,说明在 Tornado 中如何使用带有 static_url 的模板?
    • tornado/web.py 中搜索static_url
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多