Built-in filters
add
Adds the argument to the value. For example:
{{ value|add:"2" }}
If value
is 4
, then the output will be 6
.
addslashes
Adds slashes before quotes. Useful for escaping strings in CSV, for example. For example:
{{ value|addslashes }}
If value
is I'm using Django
, the output will be I'm using Django
.
capfirst
Capitalizes the first character of the value. If the first character is not a letter, this filter has no effect.
center
Centers the value in a field of a given width. For example:
"{{ value|center:"14" }}"
If value
is Django
, the output will be Django
.
cut
Removes all values of arg
from the given string.
date
Formats a date according to the given format. Uses a similar format as PHP's date()
function with some differences.
Note
These format ...
Get Mastering Django: Core now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.