I use framework Flask, python, jinja2 . I transfer the dictionary with three lists:

attendance = {'total': ['1', ' 5', ' 8', ' 12', ' 15', ' 19', ' 22', ' 26'], 'spravka': ['5'], 'unattended': ['1']} 

I want to display each value in the total list in a separate li tag. But this does not work. The value is always displayed 1. The cycle does not pass. What's wrong?

  <ul> {% set count = 0 %} {% for i in attendance.total %} <li>{{ attendance.total[count] }}</li> {% set count = count + 1 %} {% endfor %} </ul> @app.route('/protected') @app.route('/visits_s') def visits_s(): #........ attendance = fetch_attendance_data() return render_template("visits_s.html", attendance=attendance) 
  • 3
    Your ad attendance syntactically incorrect, the program will simply not start. - Sergey Gornostaev
  • The program starts. Only always displays the value 1 - lipton_v
  • So you did not add the same code to the question that is used in your program. Start with the above is impossible. - Sergey Gornostaev
  • And shouldn't total be indicated through brackets, is it a key? for item in attendance['total']: #some code - kot_mapku3
  • one
    @ kot_mapku3, jinja2 can do both. - kidig

1 answer 1

 <ul> {% for item in attendance.total %} <li>{{ item }}</li> {% endfor %} </ul>