1
.. _ref-contrib-humanize:
3
========================
4
django.contrib.humanize
5
========================
7
.. module:: django.contrib.humanize
8
:synopsis: A set of Django template filters useful for adding a "human
11
A set of Django template filters useful for adding a "human touch" to data.
13
To activate these filters, add ``'django.contrib.humanize'`` to your
14
:setting:`INSTALLED_APPS` setting. Once you've done that, use
15
``{% load humanize %}`` in a template, and you'll have access to these filters:
20
For numbers 1-9, returns the number spelled out. Otherwise, returns the
21
number. This follows Associated Press style.
25
* ``1`` becomes ``'one'``.
26
* ``2`` becomes ``'two'``.
27
* ``10`` becomes ``10``.
29
You can pass in either an integer or a string representation of an integer.
34
Converts an integer to a string containing commas every three digits.
38
* ``4500`` becomes ``'4,500'``.
39
* ``45000`` becomes ``'45,000'``.
40
* ``450000`` becomes ``'450,000'``.
41
* ``4500000`` becomes ``'4,500,000'``.
43
You can pass in either an integer or a string representation of an integer.
48
Converts a large integer to a friendly text representation. Works best for
49
numbers over 1 million.
53
* ``1000000`` becomes ``'1.0 million'``.
54
* ``1200000`` becomes ``'1.2 million'``.
55
* ``1200000000`` becomes ``'1.2 billion'``.
57
Values up to 1000000000000000 (one quadrillion) are supported.
59
You can pass in either an integer or a string representation of an integer.
64
Converts an integer to its ordinal as a string.
68
* ``1`` becomes ``'1st'``.
69
* ``2`` becomes ``'2nd'``.
70
* ``3`` becomes ``'3rd'``.
72
You can pass in either an integer or a string representation of an integer.
79
For dates that are the current day or within one day, return "today",
80
"tomorrow" or "yesterday", as appropriate. Otherwise, format the date using
81
the passed in format string.
83
**Argument:** Date formatting string as described in the :ttag:`now` tag.
85
Examples (when 'today' is 17 Feb 2007):
87
* ``16 Feb 2007`` becomes ``yesterday``.
88
* ``17 Feb 2007`` becomes ``today``.
89
* ``18 Feb 2007`` becomes ``tomorrow``.
90
* Any other day is formatted according to given argument or the
91
:setting:`DATE_FORMAT` setting if no argument is given.