0
我有Jinja自定義過濾器需要兩個參數,我打電話給我的Jinja模板內的函數,我得到一個有關位置參數的TypeError。那我的函數有兩個(正確的),但3分別給予(不正確)Jinja2自定義函數給位置參數錯誤
下面是函數代碼
# Get the total balance of a student to display for an instructor
def get_stud_balance(inst_id, stud_id):
balance = 0
stud_balance = Packages.query.filter(Packages.inst_id == inst_id, Packages.stud_id == stud_id).all()
for row in stud_balance:
balance += row.balance
return balance
這是它是如何註冊..
app.jinja_env.filters['get_balance'] = filters.get_stud_balance
這是怎麼了我想叫它..
{% for row in studs %} <!-- START for loop -->
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading"><center>{{ row.first_name }} {{ row.last_name }}</center></div>
<div class="panel-body">
<li>Cell Phone: {{ row.cell|phone }}</li>
<li>Home Phone: {{ row.home|phone }}</li>
<li>Email: {{ row.email }} </li>
<li>Birthday: {{ row.birthday|date }}</li>
<li>Gender: {{ row.gender|gender }}</li>
<li>Balance: {{ balance|get_balance(row.inst_id, row.stud_id) }}</li>
</div>
</div>
</div>
{% endfor %} <!-- /END for loop -->
我在這裏失蹤了什麼?如果我只是從文件運行它,而不是在加載模板時運行該函數而沒有問題。
這將有固定的,'