Welcome to this short Django Tip. No long story here since this is a 'Quickie'.
This is what we would achieve:
To achieve this, we would be using the humanize
module which is located in django.contrib.humanize
.
The humanize module is a collection of template filters that adds a human touch to our displayed data. Instead of spitting out the exact values in our database, it prettifies it to a nice readable format.
Let's get to work
1. Add the module to your INSTALLED_APPS
:
'django.contrib.humanize'
2. Load it up in your template:
{% load humanize %}
3. Apply the filter to your timestamp
{{ viewed_on|naturaltime }}
That's it!
The humanize
module also contains other filters. Here's a link to the the documentation.
Now go forth and make your apps human friendly.
Video Version
Top comments (0)