【发布时间】:2018-09-11 13:56:03
【问题描述】:
我在列表中有一本字典。我想访问 django 模板中的字典值。我怎么能得到那个? 视图.py
def payment_status(request):
l1=[]
cand = CandidateDetail.objects.all()
for person in cand:
for num in range(0,paid['count']):
if paid['items'][num]['email']==person.email and paid['items']
[num]['status']=='authorized':
cand_dict = {'first_name':person.first_name,
'last_name':person.last_name, 'email':person.email,
'paid':'Yes'}
l1.append(cand_dict)
return render(request, 'desk/payment_status.html',{'cand_list':l1})
html文件
<div class="col-md-10">
<h3>Candidate Payment Status</h3>
<table class="cand_list">
<tr>
<th>Name</th>
<th>Email</th>
<th>Payment Status</th>
</tr>
{% for candidate in cand_list %}
<tr>
<td>{{ candidate.first_name }} {{ candidate.last_name }}</td>
<td>{{ candidate.email }}</td>
<td>{{ candidate.paid }}</td>
</tr>
{% endfor %}
</table>
</div>
我得到的错误是 -- 无法解析余数:'[item]['first_name']' from 'cand_list[item]['first_name']'
【问题讨论】: