DEV Community

Emmanuel Okiche
Emmanuel Okiche

Posted on

3 1

Django Quick Tip #1: Human Friendly Timestamps with Django's Humanize

Welcome to this short Django Tip. No long story here since this is a 'Quickie'.
This is what we would achieve:

Tranformed timestamp

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'
Enter fullscreen mode Exit fullscreen mode

2. Load it up in your template:

{% load humanize %}
Enter fullscreen mode Exit fullscreen mode

3. Apply the filter to your timestamp

{{ viewed_on|naturaltime }}
Enter fullscreen mode Exit fullscreen mode

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

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay