I am pulling a name from a database which is stored as myname
. How do I display this inside a Django template as Myname
, with the first letter being in uppercase.

- 38,793
- 23
- 126
- 164

- 2,333
- 3
- 17
- 23
7 Answers
Using Django built-in template filter called title
{{ "myname"|title }}

- 9,914
- 3
- 52
- 82

- 38,793
- 23
- 126
- 164
-
17It works for single-word strings. But, if you have a multi-words string, it's going to upper the first letter of each single word, instead of the first letter of the string. – Valdir Stumm Junior Jan 11 '13 at 17:17
-
It is howerver not useful with apostrophes like "My friend's house" or "you're an uppercase freak" which becomes "Friend'S" and 'You\'Re'. – Timo Jan 03 '15 at 20:14
-
3This answer is wrong. |title does not make the first letter of a string uppercase. It makes first letter of each word uppercase. Example, "hello world" does not become "Hello world". It becomes "Hello World". – Marcus Lind Mar 30 '15 at 07:51
-
15Use {{ obj | capfirst }} to make uppercase the first character only. Using {{ obj | title }} makes it Camel Case. – Nrzonline Nov 18 '15 at 11:21
I know it's a bit late, but you can use capfirst:
{{ "waiting for action"|capfirst }}
This will result into "Waiting for action"
-
11This is the correct answer if you just want the first letter capitalized. – Rick Westera May 13 '16 at 02:46
-
2This will ensure the first character is uppercase, but won't ensure the rest of the string is lowercase. e.g. "hello World" would become "Hello World", not "Hello world". Which is sometimes fine, but not always :) – Phil Gyford Jan 27 '18 at 15:33
-
Yes, but this is not relevant to the question of the topic starter. Additional filters must be applied to handle extra logic. For example, @bjorn-garcia provides a solution for ensuring only the first word is capitalized. – oblalex Apr 05 '20 at 09:58
This solution also works if you have multiple words (for example all caps):
{{ "ALL CAPS SENTENCE"|lower|capfirst }}
This will output "All caps sentence".

- 339
- 3
- 5
The title
filter works fine, but if you have a many-words string like: "some random text"
, the result is going to be "Some Random Text"
. If what you really want is to uppercase only the first letter of the whole string, you should create your own custom filter.
You could create a filter like this (follow the instructions on how to create a custom template filter from this doc - it's quite simple):
# yourapp/templatetags/my_filters.py
from django import template
register = template.Library()
@register.filter()
def upfirstletter(value):
first = value[0] if len(value) > 0 else ''
remaining = value[1:] if len(value) > 1 else ''
return first.upper() + remaining
Then, you should load the my_filters file at your template, and use the filter defined there:
{% load my_filters %}
...
{{ myname|upfirstletter }}

- 4,568
- 1
- 23
- 31
-
3
-
You can see the implementation of the django defaults here: https://github.com/django/django/blob/master/django/template/defaultfilters.py – phyatt Apr 25 '18 at 13:47
It worked for me in template variable.
{{ user.username|title }}
If the user is "al hasib" then the it will return "Al Hasib"
or
{{ user.username|capfirst }}
If user is 'hasib' then the last one will return "Hasib"
Both look something like same but there's some differences.

- 87
- 1
- 5
use
{{"myname"|title}}
this will make the fist letter of each word capital

- 322
- 1
- 3
- 10
Just use {{myname | capfirst}}
In Django the template filter capfirst capatialize the first letter of a given string.

- 71
- 5