[英]Create .html file with tornado with link to static css
使用龙卷风,我想创建一个html文件并保存以供以后使用。 在html内,我想引用静态文件中的bootstrap 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>
我简化的.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:名称“ static_url”未定义
Tornado模板中使用的许多预定义名称都来自RequestHandler
,而不是模板系统本身(因为它们需要应用程序级配置)。 要按原样使用static_url
,您将需要整个服务堆栈,而不仅仅是Loader和Template.generate(或者您可以深入研究代码并重建其工作方式)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.