1

I've been stuck on this for a couple hours now, it seems that whatever I put into my for loop in my index for html doesn't print at all? Thoughts?

index method:

def index():

portfolio = db.execute("SELECT * FROM portfolio WHERE user_id = :user_id", user_id = session["user_id"])

for row in portfolio:
    symbol = row["symbol"]
    share = row["shares"]


return render_template("index.html")

index.html:

{% extends "layout.html" %}

{% block title %}
Index
{% endblock %}

{% block main %}
<table>
    <tr>
        <th>
            Symbol
        </th>
        <th>
            Name
        </th>
        <th>
            Shares
        </th>
        <th>
            Price
        </th>
        <th>
            Total
        </th>
    </tr>

    {% for row in portfolio %}
        <tr>
            <td>
                {{row.symbol}}
            </td>
            <td>
                {{row.name}}
            </td>
            <td>
                {{row.shares}}
            </td>
            <td>
                {{row.price}}
            </td>
            <td>
                {{row.total}}
            </td>
        </tr>    
    {% endfor %}


</table>
{% endblock %}

1 Answer 1

0

You have to include variables you want to pass in in the render_template call! See these two links for explanations:

Struggle passing values from Python to HTML via Flask

CS50 Pset7: rows inside the for loop are not showing up in index.html

You must log in to answer this question.

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