Site icon Tutorial

Humanizing Data

This application holds a set of Django template filters useful for adding a “human touch” to data. To activate these filters, add ‘django.contrib.humanize’ to your INSTALLED_APPS setting. Once you’ve done that, use {% load humanize %} in a template, and you’ll have access to the filters described in the following sections.

apnumber – For numbers 1 through 9, this filter returns the number spelled out. Otherwise, it returns the numeral. This follows Associated Press style. Examples:

You can pass in either an integer or a string representation of an integer.

intcomma – This filter converts an integer to a string containing commas every three digits. Examples:

You can pass in either an integer or a string representation of an integer.

intword – This filter converts a large integer to a friendly text representation. It works best for numbers over 1 million. Examples:

Values up to 1 quadrillion (1,000,000,000,000,000) are supported.

You can pass in either an integer or a string representation of an integer.

ordinal – This filter converts an integer to its ordinal as a string. Examples:

You can pass in either an integer or a string representation of an integer.

Back to Tutorial

Exit mobile version