不显示在Jinja中的数据

问题描述 投票:-1回答:1

这是我的flask应用程序中用于显示分类帐交易的一段代码。

@app.route("/")
def index():
    notes = db.execute("SELECT date, note, amount, type FROM customerdb")
    total = sum(notes)
    return render_template("index.html", total = total, notes = notes)

这是将贷方和借方相加的函数。贷方为正,借方为负。

def sum(note):
    total = 0
    for i in note:
        total += i[2]

    return total

[当我仅将notes变量传递给HTML时,该表正在工作,但是当我将总变量与注释一起传递时,只有total variable works表未显示任何数据。

<p>total: {{total}}</p>
<table class="table">
    <thead class="thead-dark">
    <tr>
        <th scope="col">Date</th>
        <th scope="col">Note</th>
        <th scope="col" id="th1">Credit</th>
        <th scope="col" id="th2">Debit</th>

    </tr>
    </thead>
    <tbody>
    {% for i in notes %}
    <tr>
        <td>{{i[0]}}</td>
        <td>{{i[1]}}</td>
        {% if(i[3] == 1) %}
            <td headers="th1">{{i[2]}}</td>
            <td headers="th2"></td>
        {% elif(i[3] == 2) %}
            <td headers="th1"></td>
            <td headers="th2">{{i[2]}}</td>
        {% endif %}
    </tr>
    {% endfor %}
    </tbody>
</table>
</div>
</div>

表中未传递总变量:enter image description here

传递总变量后的表:enter image description here

python postgresql
1个回答
0
投票

fetchall()在notes变量末尾有效。

© www.soinside.com 2019 - 2024. All rights reserved.