How to convert first letter of a string into uppercase in a Django template ?

Created July 30, 2022 | Viewed 322 | by Benjamin Edit


Examples of how to convert first letter of a string into uppercase in a Django template:

Using django builtins filter "title"

A first solution is to use title

{{"john"|title}}

gives

John

Note that

{{"john doe"|title}}

gives

John Doe

Using django builtins filter "capfirst"

Another solution is to use capfirst

{{"john doe"|capfirst}}

gives

John doe

and

{{"john"|title}}

gives

John

Using django builtins filter "capfirst"

Note: can also be used with "lower" to convert first into lowercase:

{{"JOHN DOE"|lower|title}}

gives

John Doe

References