Provides an interface between Flask web framework and humanize library.
-
Add new filter
humanize
to jinja environment, which can be easily used for humanize different objects:-
Integer numbers:
{{ 12345|humanize('intcomma') }} -> 12,345 {{ 12345591313|humanize('intword') }} -> 12.3 billion {{ 5|humanize('apnumber') }} -> five
-
Floating point numbers:
{{ 0.3|humanize('fractional') }} -> 1/3 {{ 1.5|humanize('fractional') }} -> 1 1/2
-
File sizes:
{{ 1000000|humanize('naturalsize') }} -> 1.0 MB {{ 1000000|humanize('naturalsize', binary=True) }} -> 976.6 KiB
-
Date & times:
{{ datetime.datetime.now()|humanize('naturalday') }} -> today {{ datetime.date(2014,4,21)|humanize('naturaldate') }} -> Apr 21 2014 {{ (datetime.datetime.now() - datetime.timedelta(hours=1))|humanize() }} -> an hour ago
-
-
Runtime i18n/l10n
from flask import Flask from flask_humanize import Humanize app = Flask(__name__) humanize = Humanize(app) @humanize.localeselector def get_locale(): return 'ru_RU'
{{ datetime.datetime.now()|humanize }} -> сейчас
-
In order to use UTC time instead of local time for humanize date and time methods use
HUMANIZE_USE_UTC
option, which is disabled by default:HUMANIZE_USE_UTC = True
Don't hesitate to open GitHub Issues for any bug or suggestions.