[英]Create .html file with tornado with link to static css
Using Tornado, i want to create an html file and save it to re-use it later. 使用龙卷风,我想创建一个html文件并保存以供以后使用。 Inside the html i want a reference to the bootstrap css in my static files.
在html内,我想引用静态文件中的bootstrap css。
My simplfied html looks like this, following Tornado/Python self.render("example.html") ignores CSS 在Tornado / Python self.render(“ example.html”)忽略CSS之后 ,我的简化html看起来像这样
<html>
<head>
<link rel="stylesheet" type="text/css" href="{{static_url('app/content/bootstrap.css')}}" />
</head>
<body>
{{name}}
</body>
</html>
My simplified .py looks like this: 我简化的.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()
However, i get the message: 但是,我得到消息:
NameError: name 'static_url' is not defined
NameError:名称“ static_url”未定义
Many of the predefined names for use in Tornado templates come from RequestHandler
, rather than the template system itself (because they need Application-level configuration). Tornado模板中使用的许多预定义名称都来自
RequestHandler
,而不是模板系统本身(因为它们需要应用程序级配置)。 To use static_url
as-is, you'll need the whole serving stack, not just a Loader and Template.generate (or you can dig into the code and reconstruct what it's doing). 要按原样使用
static_url
,您将需要整个服务堆栈,而不仅仅是Loader和Template.generate(或者您可以深入研究代码并重建其工作方式)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.