下面的代码正确地获取了月份编号,但我想检索月份名称,而不是数字。我尝试过在模板中使用Django日期过滤器,以及中的日历实用程序视图.py但这似乎行不通
视图.py
def ticket(request, month, year):
airline = Airline.objects.get(id=request.user.airline_id)
for ts in Timestamp.objects.filter(
airline=airline,
usage_on__year=year,
usage_on__month=month
):
pass
return TemplateResponse(request, 'club/al_history.html', {
'usage_month': month,
'usage_year': year,
'timestamp': timestamp,
})
铝.html
^{pr2}$
您可以使用日历模块:
返回
March
有关详细信息,请查看this question
您可以使用
calendar.month_name
。根据its documentation,它是:所以你只需这样使用它:
完整示例,使用
^{pr2}$en_US
区域设置:使用key=month number和value=month name创建一个字典,如下所示:
然后你可以这样用这个词:
^{pr2}$相关问题 更多 >
编程相关推荐