I am stopped at this part of Finance now.

I can print at HTML the symbol and the sum of the shares... but I don't know how to take the iteration for each symbol to the HTML to know the actual price and the name for each symbol (stock)

Here is my code for application.py

def index():
    """Show portfolio of stocks"""
    portfolio = db.execute("SELECT symbol, total(cuantas) FROM transacciones  WHERE user_id = :id GROUP BY symbol ORDER BY symbol", id=session["user_id"])
    for row in portfolio:
        share = lookup(row['symbol'])
        price = share["price"]
        name = share["name"]
    return render_template("index.html", portfolio=portfolio, name=name, price=price)

and here is my code for html:

{% for row in portfolio %}
    <td style="text-transform: uppercase">{{ row['symbol'] }}</td>
    <td>{{ (row['total(cuantas)']) }}</td>
    {% endfor %}

Thank you for your time! Regards, Santiago Correa from Argentina


Suggest you add the desired fields to the portfolio dicts. In the for row in portfolio: loop, something like row['name'] = share['name'] for example. When portfolio is sent to the html, each row will be self-contained.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .