Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a Flask app, how to print each item of a list in the new paragraphs inside my HTML page [closed]

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>
like image 969
Abhishek Gupta Avatar asked Sep 20 '15 08:09

Abhishek Gupta


1 Answers

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 %}
like image 173
marmeladze Avatar answered Sep 28 '22 08:09

marmeladze