8

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 code in the template so I was thinking of using the Context object somehow, but I have hit a brick wall. Any ideas?

Adam Pointer
  • 1,492
  • 8
  • 17

1 Answers1

12

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

template.render(**vars)
Jacob
  • 41,721
  • 6
  • 79
  • 81