如何解决Mako 模板无法识别我的函数
我有这个模板(这个是一个例子,因为真正的模板很大,要在这里添加)
<%def name="hello()">
Hi
</%def>
<%!
hello()
%>
当我运行这个
from mako.template import Template
with open("template.mako") as file:
data = file.read()
print(Template(data).render())
引发错误:
Traceback (most recent call last):
File "<input>",line 1,in <module>
File "D:\Program Files\Python\python37\lib\site-packages\mako\template.py",line 330,in __init__
(code,module) = _compile_text(self,text,filename)
File "D:\Program Files\Python\python37\lib\site-packages\mako\template.py",line 744,in _compile_text
exec(code,module.__dict__,module.__dict__)
File "memory:0x1fe35fa4548",line 16,in <module>
NameError: name 'hello' is not defined
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。