Complete the code to render a template in Flask.
from flask import Flask, render_template app = Flask(__name__) @app.route('/') def home(): return [1]('index.html')
The render_template function is used in Flask to load and render HTML templates.
Complete the code to pass a variable to the template.
from flask import Flask, render_template app = Flask(__name__) @app.route('/user/<name>') def user(name): return render_template('user.html', [1]=name)
The variable name used in the template must match the keyword argument passed in render_template. Here, name is passed.
Fix the error in the template syntax to display a variable.
<h1>Hello, [1]!</h1>In Flask templates (Jinja2), variables are displayed using double curly braces like {{ name }}.
Fill both blanks to create a dictionary in a template that filters items with quantity greater than 5.
{% set filtered = {item: qty for item, qty in inventory.items() if qty [1] 5} %}
<ul>
{% for item, qty in filtered.items() %}
<li>[2]: {{qty}}</li>
{% endfor %}
</ul>The filter uses '>' to select quantities greater than 5. The dictionary key 'item' is used to display the item name.
Fill all three blanks to loop over a list of users and display their names in uppercase.
{% for [1] in [2] %}
<p>{{ [3].upper() }}</p>
{% endfor %}The loop variable is 'user', the list is 'users', and to display the name in uppercase, use 'user.upper()'.