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

Published: July 30, 2022

Updated: December 09, 2022

DMCA.com Protection Status

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