在我的模板中,我有:
staging
Payment.x在这不输出任何东西(它是一个过滤的数据库)但是当我做payment.0或payment.1等时,它显示数据。最后,我想把它放在一个循环中,这样它显示从0到付款过滤器中的值的所有数据。任何想法为什么这不起作用?
答案 0 :(得分:0)
已修复 - 使用for循环进行迭代:
<div class="wow fadeInUp content-card" style="margin-top: 0;">
<span class="text-title center" style="color:black">Previous Orders</span>
<table class="highlight">
<thead>
<tr>
<th data-field="id">Price</th>
<th data-field="name">Date</th>
<th data-field="price">Name</th>
<th data-field="quantity">Quantity</th>
</tr>
</thead>
<tbody>
{% for payment in b.latest_event_list %}
<tr>
<td>${{payment}}</td>
<td>{{payment.date}}</td>
<td>{{payment.event}}</td>
<td>{{payment.quantity}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
我的观点:
def dashboard(request):
if request.user.is_anonymous():
messages.add_message(request, messages.ERROR, ' Please Login First before accessing the Dashboard')
return redirect("/student/login")
user = request.user
temp = Payment.objects.filter(user_id=user.id)
tempint = len(temp)
a = Payment.objects.order_by('-id')[:tempint]
a = a[::-1]
b = {'latest_event_list': a}
print a
return render(request, 'student/dashboard.html', {'b': b})
(使用materialize以表格形式放入表格格式)