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?
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.
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.
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.
Try
return render_template('template.html', **content)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With