开发者

Using dictionaries in Mako templates

Instead of passing variables to a template like so:

template.render(var1='hello', var2='world')

How can I pass a dictionary to the template and have it render in the same manner

vars = {'var1': 'hello', 'var2': 'world'}

so in the template I can display the variables as normal:

${var1} ${var2}

I don't want any extra c开发者_C百科ode in the template so I was thinking of using the Context object somehow, but I have hit a brick wall. Any ideas?


I don't know mako, but to use a dict as keyword arguments (or kwargs), you have to prepend two *:

template.render(**vars)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜