Do not know the reasons why the row in the HTML table will repeat in number of times per the length of rows. Please see my codes as follows:

application.py rows = db.execute("SELECT * FROM history WHERE hid = :id", id=sid) return render_template("history.html", rows=rows)

history.html {% for rowindex in range(rowlen) %} {{ rows[rowindex]['hsymbol'] }} {{ rows[rowindex]['hshare'] }} ${{ rows[rowindex]['hprice'] }} {{ rows[rowindex]['transacted'] }} {% endfor %}

History display

3 Answers 3


Can only guess since the code posted does not give enough info to diagnose.

  • Is it "dirty data"? Are the rows in the database multiple times, perhaps indicating a bug in buy? Verify the data using sqlite3 or phpLiteAdmin.
  • Is the rowindex loop in the html multiple times? From the available info in the question, it seems more likely the problem is in the html.
  • Checked the phoLiteAdmin that only had 4 transactions. The len(rows) also showed 4. The rowindex loop in the html in 4 times.
    – Gregory
    Sep 21, 2020 at 3:01
  • If the rowindex loop is in the html 4 times, then it will print each set of transactions 4 times. Please edit the entire html into the question, properly formatted, for clarification. Sep 21, 2020 at 10:33

Found and fixed the error. Made the change as follows:

{% for row in rows %} {{ row['hsymbol'] }} {{ row['hshare'] }} {{ row['hprice'] }} {{ row['transacted'] }} {% endfor %}


Please see I have made the changes as follows:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .