2014-10-29 48 views
3

好吧,在python运行以下命令:为什么Mako不能找到包含它的模板?

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相同的目录,这里发生了什么?

回答

5

发布后,我发现它的作品,如果第四行是mytemplate = mylookup.get_template('content.html.mako')而不是。

+1

但是如果您的模板包含具有相对路径的另一个模板,则mako仍然不起作用。 – 2017-09-21 11:00:18

相关问题