Django: Formatting numbers with commas

Its makes it easier to read data in a format such as "$1,000,000" instead of "$1000000".

Template tag

To use it as a template tag, first add "django.contrib.humanize" to your INSTALLED_APPS setting.

The in the template:

{% load humanize %}
{{ price|intcomma }}


Or in your view code:

from django.contrib.humanize.templatetags.humanize import intcomma

return "$ %s" % intcomma(price)

[ Source ]

Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog