Django: Formatting numbers with commas

0 Comments

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:

1.{% load humanize %}
2.{{ price|intcomma }}

Code

Or in your view code:

1.from django.contrib.humanize.templatetags.humanize import intcomma
2.  
3.return "$ %s" % intcomma(price)

[ Source ]

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