【发布时间】:2013-04-12 14:16:28
【问题描述】:
背景:
我的目录结构如下:
/absolute/path/to/templates
components/
component1.mak
component2.mak
template1.mak
计划是把模板目录下的模板给include一堆组件。
在 template1.mak 我有类似的东西:
<%include file="xxx.mak"/>
其中xxx 是components/component1.mak 或只是component1.mak(我尝试了两种不同的结果,详情如下)
mylookup = TemplateLookup(directories=[yyy,])
oTemplate = Template(filename='/path/to/templates/template1.mak', lookup=mylookup)
oTemplate.render(args)
其中 yyy 是 '/absolute/path/to/templates' 或 '/absolute/path/to/templates/components'
问题:
无论我使用 xxx 和 yyy 值的哪种组合,都会出现模板查找异常。 yyy 的值(查找路径)似乎对异常没有任何影响。
如果 xxx(包含标记路径)是 'components\component1.mak',则错误表示找不到文件 /absolute/path/to/templates/components/component1.mak。如果xxx 只是'component1.mak',则错误是找不到/absolute/path/to/templates/component1.mak。
问题
如何让 mako 将这些内容包含在 components 目录中?我对模板查找有什么遗漏或不了解?
【问题讨论】:
-
在模板中定义您的 xxx 调用时,您是否尝试过使用前导
/进行此操作?或者在你的 python 代码中使用原始字符串? -
@bdiamante:成功了 :) 将其发布为答案,以便我给你一些积分
标签: python mako python-3.3