在使用Mako模板中使用标签时获得Mako异常

发布于 2025-02-11 19:25:22 字数 707 浏览 1 评论 0 原文

我正在尝试使用<%include/> mako 模板中使用标签,但要获得异常。我在同一目录中都有所有文件。有人可以帮我弄清楚我在这里想念什么吗?

$cat sample1.py
from mako.template import Template
fn = "sample1.txt"
templateDef = open(fn, "r").read()
t = Template(templateDef).render()
print(t)

$cat sample1.txt
<%include file="header.html"/>
hi
<%include file="footer.html"/>

$cat header.html 
<html>
header
</html>

$cat footer.html 
<html>
footer
</html>

这是我遇到的错误:

$python3 sample1.py
mako.exceptions.TemplateLookupException: Template 'memory:0x2b80733bc3c8' has no TemplateLookup associated

语法明智,我看不到任何问题。即使所有文件都在同一目录中,我也无法正常工作。有帮助吗?

I am trying to use <%include /> tag in mako template, but getting exception. I have all the files in the same directory. Can someone help me figure out what am I missing here?

$cat sample1.py
from mako.template import Template
fn = "sample1.txt"
templateDef = open(fn, "r").read()
t = Template(templateDef).render()
print(t)

$cat sample1.txt
<%include file="header.html"/>
hi
<%include file="footer.html"/>

$cat header.html 
<html>
header
</html>

$cat footer.html 
<html>
footer
</html>

This is the error I get:

$python3 sample1.py
mako.exceptions.TemplateLookupException: Template 'memory:0x2b80733bc3c8' has no TemplateLookup associated

Syntax wise I do not see any issue. Even though all the files are in the same directory, I can't get it to work. Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罪歌 2025-02-18 19:25:23

使用Templatelookup功能

a=TemplateLookup(directories=[‘dirname’])

Temp=a.get_template(‘filename’)

Print(Temp.render())

访问

Use TemplateLookup function

a=TemplateLookup(directories=[‘dirname’])

Temp=a.get_template(‘filename’)

Print(Temp.render())

Visit
https://docs.makotemplates.org/en/latest/usage.html#mako.lookup.TemplateLookup

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文