π Hello Guys!
In this tutorial you will become familiar my favorite django template filters.
1. Timesince
If you want to show the date-time-field
of a django model in human familiar term you can use this filter like this:
{{ field_date|timesince }}
and it will return you the time like 2 days ago
format
2. Linebreaks
If you want to show the text of a field of a django model as you write in the form (with spaces, and tabs) you could use this filter in template like this:
{{ value|linebreaks }}
3. Truncatewords
If you want to display the first n
words of a django model field in the template you can use this filter. For example if you want to show the first two words of the text you can use the filter like this:
{{ text|truncatewords:2 }}
and the output will be like Hello Python ...
4. Urlize
If you want to make an url active of the text of a django model field you can use this template filter like this:
{{ text|urlize }}
5. Wordcount
If you want to show the number of words of a django model field in the template you can use this filter like this:
{{ text|wordcount }}
and it will return the number of the words in the template
6. Title
If you want to show the text of a django model field in Title Case
you can use this template filter like this:
{{ text|title }}
You can use |upper
and |lower
for respectively UPPER CASE
and lower case
.
for a detail knowledge of django template filters and tags you can visit djangotemplatetagsandfilters.com
πThank you for reading my post!
Top comments (11)
Very Useful Article!
thanks
djangotemplatetagsandfilters.com π
Great article!
Thank you Dennis, I'm also a big fan of you on youtube.
great work It was Use full
thanks a lot brother..... even I didn't know all of this existedπ
You're welcome
Great article!
Great
Awesome!