【发布时间】:2013-11-22 02:04:19
【问题描述】:
我可以像这样通过 shell 执行 python 文件:
$ python jinja.py
[代码] from jinja2 import Environment, FileSystemLoader
DIR = '/Users/username/Sites'
env = Environment(loader=FileSystemLoader(DIR))
templateVars = {
"title" : "Test Example",
"description" : "Description"
}
template = env.get_template('index.html')
print template.render(templateVars)
[/代码]
这是通过 shell 的输出:
[代码]
<html>
<head>
<title>Test Example</title>
<meta name="description" content="Description">
</head>
<body>
test dictionary
</body>
</html>
[/代码]
但是,当我在浏览器上打开 index.html 时,它不会呈现变量,我不确定文件 jinja.py 是否正在执行。
这是直接来自我的浏览器窗口的源代码:
[代码]
<html>
<head>
<title>{{ title }}</title>
<meta name="description" content="{{ description }}">
</head>
<body>
test dictionary
</body>
</html>
[/代码]
仅供参考,我没有将 jinja2 与任何框架或其他包依赖项结合使用。
任何能够提供帮助的人。
谢谢 标记
【问题讨论】:
标签: python frameworks jinja2