23

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,401
  • 3
  • 13
  • 22

2 Answers2

35

Try

return render_template('template.html', **content)
Andrey
  • 59,039
  • 12
  • 119
  • 163
24

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
  • 28,393
  • 13
  • 77
  • 72