I have tried like every combination and there is no error but Jinja won't pass any value to my index.html. Running the SQL on the DB gives the correct answer! And I See a Table with head and foot etc but no values per row.

Any help is really appreciated !

edit: sorry I don't get the html formatted correctly to post it here

my database users

my database stocks


@app.route("/") @login_required def index(): rows = db.execute("SELECT SUM(shares) as totalShares, symbol FROM stocks WHERE user_id = :user_id GROUP BY symbol HAVING totalShares > 0;", user_id = session["user_id"])

grand_total = 0
holdings = []
# determine current price, stock total value and grand total value
for row in rows:
    stock = lookup(row["symbol"])
        "symbol": stock["symbol"],
        "name": stock["name"],
        "shares": row["totalShares"],
        "price": usd(stock["price"]),
        "total": usd(stock["price"] * row["totalShares"])
    grand_total += stock["price"] * row["totalShares"]

rows = db.execute("""SELECT cash FROM users WHERE id = :user_id""", user_id = session["user_id"])
cash = rows[0]["cash"]
grand_total += cash

return render_template("index.html", holdings=holdings, cash =cash, grand_total = grand_total)



  • Is this "And I See a Table with head and foot etc" literal? The posted html has no table elements. Dec 23 '20 at 12:41
  • Well I figured out that I never actually call the index.html. Thats why I don't get any data even though I see the table which doesn't make sense for me. My workaround is to create a new template portfolio.html which I gave a button in the navbar. When I click on that the database gets a query and everything is fine. maybe still someone can explain the behavior ?
    – chris_A350
    Dec 24 '20 at 1:29
  • Not enough to go on to explain the behaviour. "never actually call the index.html"? What does it call? If you see something it calls something. Use the flask log and the browser console/network tab to track what is happening. Perhaps view the page source and copy past to html validator. The vast difference between the edited html in the question and the original html is significant. Dec 24 '20 at 12:12
  • Try to use unique variables names to store the output of the select queries e.g. rows1 and rows2 instead of using rows for both.
    – EddyBeor
    Dec 26 '20 at 13:29

You must log in to answer this question.

Browse other questions tagged .