0

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

@app.route("/")
@login_required
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 %}
  <tr>
    <td style="text-transform: uppercase">{{ row['symbol'] }}</td>
    <td></td>
    <td>{{ (row['total(cuantas)']) }}</td>
    <td></td>
    <td></td>
  </tr>
    {% endfor %}

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

1

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 .