我使用App Engine的web应用程序的模板系统(类似,如果不完全相同的Django)Python的模板帮助
通常我渲染模板,从我的静态目录/模板/作为 跟随我的主要的处理程序:
dirname = os.path.dirname(__file__)
template_file = os.path.join(dirname, os.path.join('templates', template_name))
output = template.render(template_file,template_values)
self.response.out.write(output)
对于我目前的应用程序,我想渲染一个包含在 字符串中的模板。我使用下面的代码:
t = template.Template(template_string)
c = template.Context(template_values)
output = t.render(c)
self.response.out.write(output)
它呈现模板,但不是“包括”包含在 的字符串变量。例如,字符串模板
的 “hello world {%包括 '的helloworld.html' %}”
呈现的 “Hello World”,但不会呈现 '的helloworld.html' 的内容。 我猜这与'helloworld.html'相同的目录中的字符串不是 ,但我不知道如何 指定include标签应该在'/ templates/* “ 任何帮助,将不胜感激, 阿琼