like it was stated I have a history table.

I created history.html:

{% extends 'layout.html'%}

{% block title %}
{% endblock %}

{% block content %}
  <table class="table" style="width:100%">
        <th>Transaction type</th>
        <th>Number of shares</th>
  {% for h in history %}
  {% endfor %}
{% endblock %}

And application.py history method:

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.


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.

You must log in to answer this question.

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