0

I'm looking to output my db row info though am getting nothing but a blank page instead.

Here is my python code which works:

@app.route("/")
@login_required
def index():
"""Show portfolio of stocks"""

#if(session.get("user_id") > 0):

userRows = db.execute("SELECT * FROM users WHERE id = :id", id=session.get("user_id"))
portfolioRows = db.execute("SELECT * FROM portfolio WHERE userID = :id", id=session.get("user_id"))
stockHeader = "HERE IS YOUR STOCK PORTFOLIO"


return render_template("index.html")
#else:
    #return render_template("index.html")

Here is my HTML:

        <main class="container p-5">
        {% block main %}


        <h1>{{ stockHeader }}</h1>
        {% for stock in portfolioRows %}
        <strong>Name:</strong> {{ stock.stockName }} <br>
        <strong>Price:</strong> {{ stock.stockPrice }} <br>
        <strong>Symbol:</strong> {{ stock.stockSymbol }} <br>

        {% endfor %}



        {% endblock %}
    </main>
1

The template does not know what stockHeader or portfolioRows is. You'd have to pass it like return render_template("index.html", stockHeader=stockHeader, portfolioRows=portfolioRows). First portfolioRows determines the name in the template, second portfolioRows is evaluated in the Python script and determines the value passed. Think of it as name=value, in the tempate accessed like {{ name }}

1
  • @Blaulf That worked perfectly!! Thank you for the help :-)
    – ndjustin20
    Apr 4 '18 at 3:35

You must log in to answer this question.

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