How to display month name by number?

后端 未结 4 632
囚心锁ツ
囚心锁ツ 2021-02-07 11:24

I have a number represented month and i want to replace it with month name, date filter not working:

{{ monthnumber|date:\"M\" }}

I want to pla

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 12:11

    Just in case you do not want to format a date object passed into a Django template (like the other answers clearly show), but rather you'd prefer to simply get the current date's month number; here is the built-in tag you can use to do that:

    {% now "n" %}
    

    From the docs: https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#now

    Here are the built in date tags you can use with {% now [""] %}

    https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#date

提交回复
热议问题