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 (将#修改为@)