Creating a template filter to show how many days have passed since a post was published
Not all people keep track of the date and when talking about creation or modification dates of cutting-edge information; for many of us, it is convenient to read the time difference. For example, the blog entry was posted three days ago, the news article was published today, and the user last logged in yesterday. In this recipe, we will create a template filter named days_since
, which converts dates to humanized time differences.
Getting ready
Create the utils
app and put it under INSTALLED_APPS
in the settings, if you haven't done that yet. Then, create a templatetags
Python package in this app (Python packages are directories with an empty __init__.py
file). ...
Get Web Development with Django Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.