template.render()Google App Engine(python)

Phi*_*hil 2 google-app-engine

我正在使用谷歌的webapp框架.我在get方法中使用template.render()来为我渲染模板.

我正在使用以下代码为我执行此操作

path = os.path.join(os.path.dirname(__file__), file_name)
self.response.out.write(template.render(path, template_values))
Run Code Online (Sandbox Code Playgroud)

其中file_name是要呈现的模板,template_values是包含要呈现的任何值的dict().如果我没有任何我想要呈现的值,该怎么办?我只是传入一个空dict()物体吗?对我来说这似乎不是一个很好的解决方案.我应该使用template.load()吗?

(我也无法在谷歌应用引擎上找到模板类的文档,因此我问.)

mco*_*ton 5

您可以将空字典传递给它,但它并不介意.你只需要发送一些东西.您的模板不会显示任何内容.

template_values = {}

path = os.path.join(os.path.dirname(__file__), file_name)
self.response.out.write(template.render(path, template_values))
Run Code Online (Sandbox Code Playgroud)