[英]How do you pass an array to a mako template?
我想将一个字符串数组传递给 Mako 的 render 方法,但这不起作用:
from mako.template import Template
mytemplate = Template(filename="some.template")
str = mytemplate.render(first="John", last="Smith", nicknames=[
"JJ", "Johnny", "Jon"])
print(str)
some.template =
Hello ${first} ${last}
Your nicknames are:
% for n in ${nicknames}:
${n}
% endfor
在“%”行中,您正在编写不需要转义的常规 Python 代码:
% for n in nicknames:
${n}
% endfor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.