I felt like I could understand the for loops great in c, but seem to be hitting a wall here. Some generic conceptual questions before i get into it:
1) ANSWERED. what sequence does the program run, does it read HTML first or the Python scripts first?
2) ANSWERED. what is the difference between the for loop in HTML and for loop in python?
NEED HELP:
3) Main/In depth question:
I can't seem to to get my sharesNow=lookup(share['symbol'])
to loop. My sharesOwned
in HTML are looping great, but not any thing else.
Index in python/flask:
@app.route("/")
@login_required
def index():
#get and consolidate user data in database
sharesOwned = db.execute("SELECT symbol, price, name, SUM(shares) AS quanties FROM shares WHERE id=:id GROUP by symbol, symbol ORDER by symbol", id=session["user_id"])
#loop through "position" dict
for share in sharesOwned:
sharesNow=lookup(share['symbol'])
position={
'name':sharesNow["name"],
'pricey': sharesNow['price'],
'symbol':sharesNow["symbol"]
}
rows=db.execute("SELECT * FROM users where id = :id", id = session["user_id"])
return render_template("index.html", sharesOwned=sharesOwned, position=position, name=rows[0]["username"])
index.html:
{% extends "layout.html" %}
{% block title %}
Index
{% endblock %}
{% block main %}
<h2>RESULTS:</h2>
<ul>
<li><h2> {{ name }}</h2></li>
</ul>
<table class="table table-striped">
<thead>
<th>Share Symbol</th>
<th>Shares Name</th>
<th>Number of Shares</th>
<th>Current price</th>
<th>Total value</th>
</thead>
{% for share in sharesOwned %}
<tr>
<td>{{ share.symbol }}</td>
<td>{{ position.name }}</td>
<td>{{ share.quanties }}</td>
<td>{{ position.pricey }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}