How to convert string to uppercase / lowercase in Jinja2?

Solution 1:

Filters are used with the |filter syntax:

{% elif  student.department|upper != "MATHS DEPARTMENT" %}
    Maths department
{% endif %}

or you can use the str.upper() method:

{% elif  student.department.upper() != "MATHS DEPARTMENT" %}
    Maths department
{% endif %}

Jinja syntax is Python-like, not actual Python. :-)

Solution 2:

for the capitalize

{{ 'helLo WOrlD'|capitalize }}

output

Hello world

for the uppercase

{{ 'helLo WOrlD'|upper }}

output

HELLO WORLD

Solution 3:

For Capitalize

{{ 'helLo WOrlD'|capfirst }}

For UPPER CASE

{{ 'helLo WOrlD'|upper }}

For lower case

{{ 'helLo WOrlD'|lower }}

For title

{{ 'helLo WOrlD'|title }}

For ljust

{{ 'helLo WOrlD'|ljust }}

For rjust

{{ 'helLo WOrlD'|rjust }}

For wrap

{{ 'helLo WOrlD'|wrap }}

Hope It Helps