Pass in variable to Mako template

倾然丶 夕夏残阳落幕 提交于 2020-01-24 08:59:06

问题


In Perl, by using Template Toolkit, here is what I do

Perl

my $vars = {
    name     => 'Count Edward van Halen',
};

$tt->process('letters/overdrawn', $vars)
    || die $tt->error(), "\n";

HTML

Dear [% name %],

In Mako template, how can I do so? Check through their render function, doesn't get much hint.


回答1:


Use named arguments

mytemplate.render(myvar1="var1", mydict=dict())

In the mako side you'd do

${myvar1}
% for val in mydict:
    ${val}
% endfor


来源:https://stackoverflow.com/questions/4161464/pass-in-variable-to-mako-template

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!