I'm building a Flask app which is supposed to return all the items in a list as a new line in the HTML page.
For example:
list = [1,2,3,4]
I want to print each item in list
as a new paragraph in my HTML page, like here:
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
You should better follow the flaskr tutorial on flask web site. It can give you the idea how to pass local variables to the template.
@app.route('/')
def your_view():
your_list= [1,2,3,4]
return render_template('your_view.html', your_list=your_list)
then in your jinja template, iterate over this list.
{% for your_list_element in your_list %}
<p>{{ your_list_element }} </p>
{% endfor %}
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