0

I tried to run the program and encountered this error:

enter image description here

My code:

@app.route("/")
@login_required
def index():
    """Show portfolio of stocks"""
    # Selecting from "transaction" table all of the stocks the currently logged in user owns
    stocks = db.execute("SELECT symbol, SUM(shares) as shares FROM transactions where userID = :id 
GROUP BY symbol ORDER BY symbol", id = session["user_id"]) # return a table or a list of dictionaries?

    stocks_total_value = 0

    # Iretate over each stock of the list of stocks (Each stock is a dictionary)
    for stock in stocks:
        quote = lookup(stock["symbol"])
        stock["name"] = quote["name"]
        stock["price"] = quote["price"]
        stock["total"] = stock["shares"] * stock["price"]
        stocks_total_value = stocks_total_value + stock["total"]

    user_cash = db.execute("SELECT cash from users where id = :id", id = session["user_id"])
    current_cash_balance = user_cash[0]["cash"]
    grand_total = stocks_total_value + current_cash_balance

    return render_template("index.html", stocks = stocks, current_cash_balance = usd(current_cash_balance),
                           grand_total = usd(grand_total))

I understand that lookup(symbol) will return a dictionary with keys are "name", "price", "symbol" so quote["name"] should have not been not subscriptable.

What did I miss or misunderstand here?

You must log in to answer this question.

Browse other questions tagged .