Hi Guys!
Here are some template filters you can make use of in your code.
In this whole project we will be using this django model as our reference in each field we use
class BLog(models.Model):
image = models.ImageField(upload_to="blog_images", null=True)
title = models.CharField(max_length=200, blank=True, null=True)
description = models.TextField(blank=True, null=True)
date_created = models.DateTimeField(auto_now=True)
1. Linebreaks
This is used when you want show a text or a sentence as you have it stored in your django model with the spaces and tabs. This can be mostly used with the models which have Textfields in them. for example you have a blog model which has a field description = models.TextField() in your django template you can write it as
{{ blog.description|linebreaks }}
2. Timesince
This is used when you want to show a date time field
of a django model in human familiar term especially in blogs or any other chat systems;
{{ blog.date_created|timesince }} # This will appear as "5 days ago"
3.Truncatewords
This is used when you want to display the first “n"
words of a Django model field in the template. for example, if you want to show the first 10 words of a particular field;
{{ blog.description|truncatewords:10 }}
# THe above like will be showing the first 10 words in that field
4.Urlize
This is used when you want to make url active of the text of a django model field.
you can also apply this with the linebreaks to make it more nice.
{{ blog.description|urlize }}
#the one below is the addition of urlize and linebreak. this will bring out the spaces and make all links clickable
{{ blog.description|linebreaks|urlize }}