我能够通过shell执行python文件如下:
$ python jinja.py
来自jinja2导入环境的代码,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)/code
下面是通过外壳的输出:
代码
<html>
<head>
<title>Test Example</title>
<meta name="description" content="Description">
</head>
<body>
test dictionary
</body>
</html>/code
但是,当我在浏览器上拔出index.html时,它不会呈现变量,我甚至不确定文件jinja.py是否正在执行。
下面是直接来自我的浏览器窗口的源代码:
代码
<html>
<head>
<title>{{ title }}</title>
<meta name="description" content="{{ description }}">
</head>
<body>
test dictionary
</body>
</html>/code
Fyi,我不会将jinja2与任何框架或其他包依赖结合使用。
任何能帮忙的人。
谢谢马克
发布于 2013-11-23 20:38:43
您的http://www.example.com/index.html应该得到一个脚本,它使用jinja来呈现HTML。您需要一个像中的webapp2这样的框架来处理GET。
我找到了本教程:https://www.youtube.com/watch?v=XyGW0ExGHDQ或use:https://developers.google.com/appengine/docs/python/gettingstartedpython27/introduction
https://stackoverflow.com/questions/20135645
复制相似问题