0

like it was stated I have a history table.

I created history.html:

{% extends 'layout.html'%}

{% block title %}
    History
{% endblock %}

{% block content %}
  <table class="table" style="width:100%">
    <thead>
      <tr>
        <th>Transaction type</th>
        <th>Timestamp</th>
        <th>Share</th>
        <th>Price</th>
        <th>Number of shares</th>
      </tr>
    </thead>
  {% for h in history %}
    <tr>
      <td>{{h.transactionType}}</td>
      <td>{{h.timestamp}}</td>
      <td>{{h.share}}</td>
      <td>{{h.price}}</td>
       <td>{{h.numOfShares}}</td>
    </tr>
  {% endfor %}
</table>
{% endblock %}

And application.py history method:

@app.route("/history")
@login_required
def history():
    """Show history of transactions."""

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

    return render_template("history.html", history = history)

I'm guessing that the select succeeds, since it throws no error. However, when I press history button, nothing gets rendered. Not even the table head. Empty screen with only layout.html present, nothing else.

0

It is not enough to just store the data from the SELECT statement into a variable. You need to organize that data into rows which Jinja and Python can then iterate through. By saying history=history you are basically passing in a big blob of data which Jinja has no idea how to deal with. Instead you should think of the fields you need for each row and construct a list of rows that you can pass to Jinja. At least that's the method I used and it worked well for me.

| improve this answer | |

You must log in to answer this question.

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