Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
How can I use localize template tag with date filter in Django?

According to Django docs, the localize template tag allows for more fine-grained control of localization in templates than the general USE_L10N = True setting.

However, turning localize on doesn't produce the same result as setting USE_L10N = True when combined with the date filter.

# USE_L10N = True in settings.py

{% load l10n %}
{{some_datetime_value|date}}

# Date is shown and localized

vs

# USE_L10N = False in settings.py

{% load l10n %}
{% localize on %}
{{some_datetime_value|date}}
{% endlocalize %}

# Date is shown and NOT localized

Why are the two results different? How can I make the localize tag localize correctly in combination with the date filter?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As Brian Destura pointed out in the comments this looks like a Django bug.

Converting the datetime object to a date object before passing it to the template might work for a single object, but is very inconvenient if you have to access model fields that are stored as datetime (e.g. within for loops).

In case someone faces the same issue, a custom filter that converts the datetime object to a date object worked for me (this is actually what the in-built date filter is supposed to do).

custom_tags.py

@register.filter
def get_date(value):
    return value.date()

template.html

{% load i10n %}
{% load custom_tags %}

{% localize on %}
{{some_datetime_value|get_date}}
{% endlocalize %}

#localizes the format correctly
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!