Make the First Letter of Word Uppercase Inside a Django Template

To capitalize the first character in a string in a Django template, use the built-in capfirst function.

 

Django capfirst Example

To use capfirst, pass it after a string using a | (pipe) like this:

 

{{ 'hello'|capfirst }}
Hello

 

You can of course pass variables to capfirst too:

 

{{ i.word|capfirst }}
This is a string.

 

That's it! You can now ensure strings start with a capital letter. If you need title casing, look at the example below.

 

Capitalize the First Letter of Every Word in Django Template

If you need title casing, pipe in the built-in Django title function. Here is an example:

 

{{ 'a string of text.'|title }}
A String Of Text
django