Using filters

Filters are an effective way to modify the data before sending it to the template. We will look at some examples of filters in the following sections to understand them better.

The upper and lower filters

The lower filter converts into lowercase letters, and the upper filter converts into uppercase letters. The example given in the subsequent sections contains the my_hello variable, which equals Hello World!

The lower filter

The code for the lower filter is as follows:

<span> {{ my_hello | lower }} </span>

This code generates the following HTML code:

<span> hello world! </span>

The upper filter

The code for the upper filter is as follows:

<span> {{ my_hello | upper }} </span>

This code generates the following HTML code:

<span> HELLO WORLD! ...

Get Django: Web Development with Python 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.