27.2 Custom Template Filters

Before jumping into building custom template tags, we detour and create a custom template filter. A filter is simply a tool that changes a string in the template. We saw the length, pluralize, title, date, and linebreaks filters (as well as a few others) in Chapter 4: Rapidly Producing Flexible HTML with Django Templates. In this section, we create our own filter.

The goal of our filter, called obfuscate, is to take an email and change it. Robots are known for scrapping the web in an attempt to find information, and by printing people’s emails on our website, we are doing them a disservice. Instead, we will print a string that is human understandable but (hopefully) unintelligible to robots. We will use it in startup_detail.html ...

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.