Django separate thousands in template

后端 未结 2 1513
傲寒
傲寒 2021-02-07 13:30

My model is returning a Decimal(1234567.50), I can\'t seem to display the Decimal with a thousands separator. Does Django have a way to do this? Do I need to create my own templ

2条回答
  •  温柔的废话
    2021-02-07 14:08

    One easy way is to import locale and do the formatting in your view function.

    Even easier to read this: http://docs.djangoproject.com/en/dev/topics/i18n/#overview

    For format localization, it’s just necessary to set USE_L10N = True in your settings file. If USE_L10N is set to True, Django will display numbers and dates in the format of the current locale. That includes field representation on templates, and allowed input formats on the admin.

提交回复
热议问题