【发布时间】:2021-07-27 09:04:03
【问题描述】:
我正在尝试传递一个名为 eligable 的列表,以便我可以在我的网站上显示,但是当我运行我的网站时,它不会显示该列表。我不明白出了什么问题。
代码:
def specificDate(response):
empName = employeeName.objects.all()
eligable = []
if 'checkEmployee' in response.POST:
n = response.POST.get("nameEmployee")
specDate = response.POST.get("date")
if employeeName.objects.filter(employee=n).exists() and Name.objects.filter(date=specDate).exists():
emp = employeeName.objects.get(employee=n)
t = Name.objects.get(name=emp, date=specDate)
overT = Name.objects.filter(name=emp, overtime=True)
for item in overT:
eligable.append(item.date)
checkIn = t.timeIn.strftime("%H:%M:%S")
checkOut = t.timeOut.strftime("%H:%M:%S")
datee = datetime.strptime(specDate,'%Y-%m-%d')
print("Here:: ",t.date)
print("Month:: ",datee.month)
messages.info(response, checkIn + ' - ' + checkOut)
return redirect('/specificDate')
else:
messages.info(response, 'Name does not exist')
else:
pass
return render(response, "main/specificDate.html", context={"empName":empName, "eligable":eligable})
这是打印我的列表的html:
{% for item in eligable %}
<div class="pad3">
{{item}}
</div>
{% endfor %}
【问题讨论】:
-
你在div下面添加
{% endfor %}了吗 -
@Poornaka 是的,我在复制代码时错过了它
-
问题是重定向的时候POST请求数据不能走
-
尝试返回正常渲染
-
没关系,我尝试了 emril 的答案,现在可以了。感谢您的帮助
标签: python html django list templates