为什么Mako无法找到与其包含的模板旁边的模板?
好的,运行这个Python代码:
from mako.lookup import TemplateLookup
from mako.template import Template
mylookup = TemplateLookup(directories=['/home/user/webapps/app/www/templates/'])
mytemplate = Template(filename='/home/user/webapps/app/www/templates/content.html.mako', lookup=mylookup)
print (mytemplate.render(title="Title", content={'hi'}))
当这段代码是content.html.mako
文件的开头时:
## content.html.mako
<%inherit file="frame.html.mako"/>
我得到了这个结果:
mako.exceptions.TemplateLookupException: Cant locate template for uri '/home/user/webapps/app/www/templates/frame.html.mako'
但是frame.html.mako
和content.html.mako
在同一个文件夹里,怎么会这样呢?
1 个回答
8
在我发这个帖子后,我发现如果把第四行改成 mytemplate = mylookup.get_template('content.html.mako')
,就可以正常工作了。