【问题标题】:Why can't Mako locate a template beside the one that's including it?为什么 Mako 不能在包含它的模板旁边找到一个模板?
【发布时间】:2014-12-25 17:10:18
【问题描述】:

好的,在 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.makocontent.html.mako在同一个目录下,这是怎么回事?

【问题讨论】:

    标签: python linux mako


    【解决方案1】:

    发布此内容后,我发现如果第 4 行是 mytemplate = mylookup.get_template('content.html.mako'),则它可以工作。

    【讨论】:

    • 但是,如果您的模板包含另一个具有相对路径的模板,mako 仍然无法工作。
    猜你喜欢
    • 2013-10-18
    • 2011-03-23
    • 2011-04-28
    • 2011-06-16
    • 1970-01-01
    • 2012-12-25
    • 2023-01-14
    • 2013-04-26
    • 2012-08-15
    相关资源
    最近更新 更多