Format numbers in django templates

前端 未结 13 1172
清歌不尽
清歌不尽 2020-11-29 17:22

I\'m trying to format numbers. Examples:

1     => 1
12    => 12
123   => 123
1234  => 1,234
12345 => 12,345

It strikes as a

13条回答
  •  一向
    一向 (楼主)
    2020-11-29 18:20

    Django's contributed humanize application does this:

    {% load humanize %}
    {{ my_num|intcomma }}
    

    Be sure to add 'django.contrib.humanize' to your INSTALLED_APPS list in the settings.py file.

提交回复
热议问题