I'm currently struggling with index(). In buy() I created the custom table with, one might say, too many columns. Among others are symbol, name, shares, price, total.
So far I was able to plug some of the necessary inputs in index.html. except for the current price per share. It somehow takes only one current price and fills the table with it.
@app.route("/")
@login_required
def index():
"""Show portfolio of stocks"""
stocks = db.execute("SELECT symbol, name, shares, total FROM transactions WHERE user_id = :user_id GROUP BY symbol",
user_id=session['user_id'])
for stock in stocks:
prices = lookup(stock['symbol'])
return render_template("index.html",stocks=stocks, prices=prices['price'])
I've tried different variations, one where I create a variable with the current price, putting an indent on returning the template and trying to put the current prices into a new list/dict and somehow adding it to the stocks. This seemed a lot more complicated than it should be I'm sure. Or maybe I've been looking at the screen for too long and am going blank. Thanks for your help!
{% extends "layout.html" %}
{% block title %}
Portfolio
{% 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>
{% for items in stocks %}
<tbody>
<tr>
<td>{{ items['symbol'] }}</td>
<td>{{ items['name'] }}</td>
<td>{{ items['shares'] }}</td>
<td>{{ prices }}</td>
<td>{{ items['total'] |usd }}</td>
</tr>
</tbody>
{% endfor %}
<tr>
</table>
{% endblock %}