I am stuck on index() in finance. I have a working SQL function which compiles all the transactions made by the user and sums the shares of all the repeating stocks - ie creating a list of owned stocks and how many shares there are. I have checked that the SQL function returns correct data. I have a for loop which creates a list with all the needed data points for the table in index (current price, total holding price, stock name, stock symbol...) This list is passed into the html table but the html only displays the headings of the table.
Here's app.py:
@app.route("/")
@login_required
def index():
"""Show portfolio of stocks"""
id = session["user_id"]
stocks = db.execute("SELECT stock_name, SUM(shares), stock_symbol FROM transactions GROUP BY stock_name HAVING user_id = ?", id)
portfolio = []
for stock in stocks:
stock_name = stock["stock_name"]
stock_symbol = stock["stock_symbol"]
shares = stock["SUM(shares)"]
quote = lookup(stock_symbol)
current_price = quote["price"]
shares_value = current_price*shares
portfolio.append([stock_name, stock_symbol, shares, current_price, shares_value])
return render_template("index.html", portfolio = portfolio)
Here's index.html:
{% extends "layout.html" %}
{% block title %}
Quoted
{% endblock %}
{% block main %}
<h2>Your portfolio</h2>
<table>
<thead>
<tr>
<th>Stock Name</th>
<th>Stock Symbol</th>
<th>Total Shares</th>
<th>Current Stock Price</th>
<th>Total Shares Value</th>
</tr>
</thead>
<tbody>
{% for stock in portfolio %}
<tr>
<td>{{ stock.stock_name }}</td>
<td>{{ stock.stock_symbol }}</td>
<td>{{ stock.shares }}</td>
<td>{{ stock.current_price }}</td>
<td>{{ stock.shares_value }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
And finally here's the screenshot of the output:
Please help me