Django shorts: #1 Humanize

Arno Pretorius
1 min readSep 25, 2022


Examining the humanize template filter in Django.

Photo by Faisal on Unsplash

Django comes with a set of pre-built template filters which are used to give a ‘human touch’ to our data. One of the most commonly used template filters in known as the natural time filter.

What is the ‘natural time filter’ used for?

The natural time filter can be used to translate time for us in a more readable format.

In this example we will be translating the 03 August 2019 22:45:47 into 13 seconds ago. The time now is 22:46:00.




Step 1:

You need to add the Django Humanize app to your installed apps, as follows:

INSTALLED_APPS = ['django.contrib.auth',
django.contrib.humanize', # Django Humanize ]

Step 2:

The next step is to load the humanize template tag in your html template:

<!-- index.html -->{% load humanize %}

Step 3:

Now apply the natural time filter to your code:

<!-- index.html -->{% load humanize %}{% for posted in datePosted %} <p> Last posted at: {{|naturaltime }} {% endfor %}


Originally published at on September 25, 2022.



Arno Pretorius

Hi, I’m Arno… I love cloud computing and django web development and I want to share my knowledge and experiences with you.