21

There has to be a way to do this... but I can't find it.

If I pass one dictionary to a template like so:

@app.route("/")
def my_route():
  content = {'thing':'some stuff',
             'other':'more stuff'}
  return render_template('template.html', content=content)

This works fine in my template... but is there a way that I can drop the 'content.' , from

{{ content.thing }}

I feel like I have seen this before, but can't find it anywhere. Any ideas?

GMarsh
  • 2,171
  • 2
  • 12
  • 22

2 Answers2

30

Try

return render_template('template.html', **content)
Andrey
  • 57,904
  • 11
  • 115
  • 158
23

You need to use the ** operator to pass the content dict as keyword arguments:

return render_template('template.html', **content)

This is effectively the same as passing the items in the dict as keyword arguments:

return render_template(
    'template.html',
    thing='some stuff',
    other='more stuff',
)
georgebrock
  • 26,147
  • 12
  • 74
  • 72