Django separate thousands in template

旧城冷巷雨未停 提交于 2019-12-09 05:37:01

问题


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 template filter?

Thanks.


回答1:


You can use the intcomma filter, but I don't think it will work on Decimal objects and it works on Decimal objects. You'll have to convert to float/string first.




回答2:


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.



来源:https://stackoverflow.com/questions/2270369/django-separate-thousands-in-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!