Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing python dict to template [duplicate]

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?

like image 277
GMarsh Avatar asked Feb 18 '16 01:02

GMarsh


People also ask

Can you make a copy of Dictionary Python?

Python Dictionary copy()The dict. copy() method returns a shallow copy of the dictionary. The dictionary can also be copied using the = operator, which points to the same object as the original. So if any change is made in the copied dictionary will also reflect in the original dictionary.

How do you shallow copy a Dictionary in Python?

The simplest way to create a copy of a Python dictionary is to use the . copy() method. This method returns a shallow copy of the dictionary.

What does DICT items () method return?

Python Dictionary items() Method The items() method returns a view object. The view object contains the key-value pairs of the dictionary, as tuples in a list.


1 Answers

Try

return render_template('template.html', **content)
like image 172
Andrey Avatar answered Sep 27 '22 19:09

Andrey