I am in desperate need of help, since the index method is the last method I have left to finish for this pset! So far, my index code works partially - as in, only the values I passed in from my portfolio database (symbol and name) are shown correctly, while the last three fields I tried to iterate over, (shares, price, and total) are not outputted. Can you please help me spot my error in the code below? I believe it must be in either my while loop, my html for loop, or both...
def index():
rows = db.execute("SELECT symbol, name, sum(quantity) FROM portfolio WHERE id = :user_id GROUP BY symbol HAVING sum(quantity) > 0 ORDER BY symbol", user_id=session["user_id"])
if not rows:
return render_template("emptyindex.html")
i = -1
shares = []
price = []
total = []
while(True):
i = i + 1
try:
result = lookup(rows[i]["symbol"])
shares.append(int(rows[i]["sum(quantity)"]))
price.append(float(result["price"]))
total.append(int(rows[i]["sum(quantity)"])*price[i])
except:
break
return render_template("index.html", rows=rows, price=price, total=total, shares=shares)
Here's my html
{% extends "layout.html" %}
{% block title %}
History
{% endblock %}
{% block main %}
<table class="table table-striped">
<thead>
<tr>
<th>Symbol</th>
<th>Name</th>
<th>Shares</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
{% for row in rows %}
<tr>
<td>{{ row.symbol }}</td>
<td>{{ row.name }}</td>
<td>{{ shares[row] }}</td>
<td>${{ price[row] }}</td>
<td>${{ total[row] }}</td>
</tr>
{%endfor%}
</tbody>
</table>
{% endblock %}
rows
,shares
,price
, andtotal
right before you render the index?