Format Dates and Numbers

A snippet showing how to localize dates and numbers.


# settings.py (relevant)

USE_I18N = True
USE_L10N = True  # enables localization of numbers/dates
USE_TZ = True
      



{% load l10n %}
{% load i18n %}

{% trans "Today is" %}: {{ today|date:"DATE_FORMAT" }}

{% trans "Total price" %}: {{ total_price|localize }}

{% trans "Unlocalized price" %}: {{ total_price|unlocalize }}

Explanation:
  • Use |localize / |unlocalize filters; use DATE_FORMAT, DATETIME_FORMAT.
  • Dates and numbers render according to the active locale and formatting settings.
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.