4.5.4 Controlling the Output of Variables with Template Filters title
, length
, and pluralize
We are now outputting the correct data, but it’s not very pretty: consider how neither django nor web is capitalized. Remember from Chapter 3 that, for alphabetization reasons, all of our tags are stored in the database in lowercase. When we display them to the user, we clearly don’t want to display them this way. We need to capitalize our content.
In addition to printing variables and providing template tags for logic, templates provide the ability to interact with variables via template filters. Template filters allow developers to sort, modify, and count lists; to format a Python date object into a pretty string; and to modify strings, such as to change ...
Get Django Unleashed 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.