我正在尝试获取一笔交易的所有发票。因为存在部分支付的可能性,所以这就是为什么我需要获得交易记录的原因。我在当前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 %}