Python Django时间域格式

Python Django时间域格式,python,django,time,format,models,Python,Django,Time,Format,Models,我的时间是这样的:“上午10点,中午”。我想要的格式是:10:00,12:00,15:00等等。 我已在我的html文件中尝试: {{ value|time:"H:M" }} 我也尝试了我的设置 TIME_INPUT_FORMATS = ('%H:%M',) 没用 在我的模型中,我有: time = models.TimeField(blank=True, null=True) 视图.py times= Hours_classes.objects.all() context = {'tea

我的时间是这样的:“上午10点,中午”。我想要的格式是:10:00,12:00,15:00等等。 我已在我的html文件中尝试:

{{ value|time:"H:M" }}
我也尝试了我的设置

TIME_INPUT_FORMATS = ('%H:%M',)
没用

在我的模型中,我有:

time = models.TimeField(blank=True, null=True)
视图.py

times= Hours_classes.objects.all()
context = {'teacher_id': teacher_id,
           'query_results': query_results,
           'times': times}
return render(request, 'planner/teacher.html', context)
class Hours_classes(models.Model):
    time_start = models.TimeField(blank=True, null=True)
    time_end = models.TimeField(blank=True, null=True)
teacher.html

<tr>
<th></th>
{% for item in times %}
    <th>{{ item.time_start|time:"H:M" }} - {{ item.time_end|time:"H:M" }} </th>
{% endfor %}
</tr>
“H:M”
不是传递给的有效格式。您需要使用:

{{ value|time:"H:i" }}

在您的模型中,时间的开始和结束是如何定义的?如果没有这个:|时间:“H:M”它会以这种奇怪的格式显示时间。有了这个,它根本不显示。我添加了我的模型