我想使用循环来创建列,并在其中显示向前的日期.下面的代码正确地显示了控制台中的所有内容,但我不知道如何向用户显示它.
list=[1,2,3,4,5,6]
for l in list:
date = datetime.date.today()
next_date=date+timedelta(days=l)
print(next_date)
{% for l in l %}
<p>{{ l }} - {{next_date}}</p>
{% endfor %}
显示六个带编号的行,但每个行都有相同的日期,我想从今天的日期到6天后的日期.
我try 了此方法,但收到错误:‘DateTim.Date’对象不可迭代.‘
{% for l in next_data %}
<p>{{ l }} </p>
{% endfor %}
我想提前6天显示日期,现在它的工作原理是每个日期都有一个变量,我希望它在循环的基础上工作和显示
def Schedule(request):
date = datetime.date.today()
next_date1=date+timedelta(days=1)
next_date2=date+timedelta(days=2)
next_date3=date+timedelta(days=3)
next_date4=date+timedelta(days=4)
next_date5=date+timedelta(days=5)
next_date6=date+timedelta(days=6)
report=Submissions.objects.filter(Q(execution_date=date) | Q(execution_date=next_date1) | Q(execution_date=next_date2) | Q(execution_date=next_date3) | Q(execution_date=next_date4) | Q(execution_date=next_date5) | Q(execution_date=next_date6), status=4)
context={
'date':date,
'report':report,
'next_date1':next_date1,
'next_date2':next_date2,
'next_date3':next_date3,
'next_date4':next_date4,
'next_date5':next_date5,
'next_date6':next_date6,
}
return render(request, 'staff/work_schedule.html', context)
<table class="table table-striped table-hover">
<div style="width: 100%;background-color: rgb(0, 0, 0);color: white;font-weight: 800;font-size: 12px;">{{date|date:'d.m.Y'}}</div>
<tbody>
{% for qs in report %}
{% if qs.execution_date|date:'d.m.Y' == date|date:'d.m.Y' %}
<tr style="font-size: 10px;text-align: center;">
<th style="width: 8%;"><a style="text-decoration: none;color: black;" href="{% url 'system:ReportCard' qs.submissions_number_id qs.created %}">{{qs.client.user.get_full_name}}, tel.:{{qs.client.phone_number}}</a></th>
<th style="width: 8%;">{{qs.client.post_code}} {{qs.client.city}}, ul.{{qs.client.street}}</th>
<th style="width: 30%;">{{qs.contents|linebreaks|truncatewords_html:50}}</th>
<th style="width: 30%;">{{qs.details_planned_service|linebreaks|truncatewords_html:50}}</th>
<th style="width: 20%;"><a style="text-decoration: none;" href="{% url 'system:StatusUpdate' qs.submissions_number_id qs.created %}?next={{ request.path|urlencode }}"><span style="font-weight: 600;color: green;">{{qs.get_status_display}}</span></a></th>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>