python - 为什么我的 For 循环在 django 模板中不起作用
问题描述
我正在尝试获取一笔交易的所有发票。因为有部分支付的可能性,这就是为什么我需要获取交易历史。我已经在我当前的 HTML 中包含了另一个 HTML,其中包含 'include' 和 with。但在 for 循环结束时,它没有显示任何内容,同时也没有错误。
这是我的views.py:
def transaction_history(request, transaction_id):
transaction = get_object_or_404(Transaction, pk=transaction_id)
invoices = Invoice.objects.filter(transaction=transaction).order_by('-created_at')
return render(request, 'front/transaction_history.html', {'invoices': invoices, 'transaction': transaction })
这是我的模板:
{% for invoice in invoices%}
<tr>
<td>{{ invoice.created_at }}</td>
<td>{{ invoice.created_by }} </td>
<td>{{ invoice.amount|floatformat:-2 }}</td>
{% for item in transaction %}
<td>{{ item.is_payed }}</td>
{% endfor %}}
</tr>
{% endfor %}
这是我的包含链接:
{% include 'front/transaction_history.html' with invoices=invoices only %}
解决方案
推荐阅读
- laravel - Laravel Blade 仅在未登录时显示
- ag-grid - 通过 setColumnDefs 设置新列定义不再起作用
- excel - 连接两个 IF 语句
- ruby-on-rails - Rails i18n 和 EasyTranslate
- java - Runnable 和 Thread 对象的打印顺序
- webpack - 如何使用 webpack 替换 Javascript 中的字符串
- javascript - Java 脚本 - 将 addeventlistener 函数中的一个变量传递给另一个 addeventlistener 函数
- powershell - Powershell -scriptblock 作业监控和编排
- sql - SQL get 从选择子查询中选择多个名称
- python - 无需输入文件夹名称即可导入自定义模块?