class StringTemplate(webapp.RequestHandler):
def get(self):
import django.template
mytemplate = "<html>...</html>"
t = django.template.Template(mytemplate)
fake_path = os.path.abspath("main.py") # or any uploaded file
template.template_cache[fake_path] = t
self.response.out.write(template.render(fake_path, {})
对于webapp的
template.render()
使用非基于文件的模板没有官方支持的方法下面是一个不受支持的方法,适用于1.5.1(以后很可能而不是):
使用
app.yaml
是因为模板缓存使用模板的绝对路径作为键,因此任何真正的文件都将作为伪模板源。但这是一个很可能会改变的实现细节。在从“googleappengine”标签判断,我假设您所说的是
google.appengine.ext.webapp
提供的模板引擎?根据documentation:“为了方便起见,webapp模块包括Django的模板引擎”。所以看看Django docs for templates。。。在据我所知,您应该能够执行以下操作(我假设
my_model.description
包含模板字符串?)公司名称:(看看template.py的webapp代码可能也很有用)
相关问题 更多 >
编程相关推荐