DJANGO CHEAT SHEET
Version 1.5
DATETIME_FORMAT Long date & time
SHORT_DATETIME_FORMAT Short date & time
DATE_FORMAT Long date
SHORT_DATE_FORMAT Short date
TIME_FORMAT Time
a
A
y
Y
F
E
M
b
N
n
m
d
j
S
l
D
w
a.m.
or p.m.
AM or PM
13
2013
January
(localised full date form)
Jan
jan
Jan.
(A.P.)
1 to 12
01
to 12
01
to 31
1 to 31
suffix: st, nd, rd or th
Friday
Fri
0
(Sun) to 6 (Sat)
Template date formats
Localized
AM & PM
Year
Month
Day
Day of week
f
P
H
G
h
g
i
s
u
1, 1:30 1 a.m.
1 a.m. 1:30 p.m.,
midnight , noon
00
to 23
0 to 23
01 to 12
1 to 12
00
to 59
00
to 59
000000
to 999999
Time
Hour
Minutes
Seconds
µs
T
e
O
Z
I
L
z
t
W
o
TZ code: EST, CET
TZ name: GMT, -500, US/Eastern
TZ offset: +0200
TZ offset (sec): -43200 to 43200
DST in effect: 1 or 0
Is leap year: True or False
Day of year: 0 to 365
Days in month: 28 to 31
Week number: 1 to 53
Week-numbering year: 2013
Timezone
Misc
c
r
U
ISO 8601: 2013-03-28T09:47:23.538501+02:00
RFC 2822: Thu, 21 Dec 2000 16:01:07 +0200
Unix time: 1364471243
Standards
Talented developers apply at www.mercurytide.co.uk/careers
{% autoescape on|off %} — {% endautoescape %}
{%
block name %} — {% endblock %}
{%
comment %} — {% endcomment %}
{%
csrf_token %}
{%
cycle "even" "odd" [as name [silent]] %}
{%
cycle name %}
{%
debug %}
{%
extends template %}
{%
filter filter1|filter2 %}
{%
firstof var1 var2 ... default %}
Does not auto-escape
{% for var[...] in list %} — [{% empty %}] — {% endfor %}
forloop.counter forloop.counter0
forloop.revcounter forloop.revcounter0
forloop.first forloop.parentloop
forloop.last
{% if expression %} — [{% elif expression %}] —
[{% else %}] — {% endif %}
Comparisons: == != < <= > >= in not in
Boolean: and or not
{% ifchanged [var1] [var2 ...] %} — {% endifchanged %}
{%
include template [with name=value ... [only]] %}
{%
load library ... %}
{%
load tag ... from library %}
{%
now [timeformat] %}
{%
regroup list by attr as name %}
{%
spaceless %} — {% endspaceless %}
{%
ssi path [parsed] %}
{%
templatetag openblock %}
open|close...block|variable|brace|comment
{% url "[app:]viewname" [arg ...] [kwarg=value ...] [as name] %}
{%
verbatim [name] %} — {% endverbatim [name] %}
{%
widthratio value maxvalue maxwidth %}
= value / maxvalue * maxwidth
{% with name=value[...]%} — {% endwith %}
|add: number
|divisibleby
: number
|filesizeformat
|floatformat[:
decimal_places]
|get_digit:
position
position 1 = 1’s, 2 = 10’s
|pluralize[: "y,ies”]
|date
: format
|time
: format
|timesince[:
datetime]
|timeuntil[:
datetime]
|default:
value
|default_if_none:
value
|dictsort:
key
|dictsortreversed
: key
|pprint
|stringformat:
format
|yesno[:
"yes,no[,none]"]
|length
|length_is
: length
|first
|last
|random
|join:
string
|slice:
"1:9"
|make_list
|unordered_list
|apnumber
|
intcomma
|intword
|naturalday[:
format]
|naturaltime
|ordinal
|language_name
|language_name_local
|bidi
|localize
|unlocalize
|localtime
|timezone:
tz_name
|utc
|safe
|safeseq
|escape
|force_escape
|escapejs
|addslashes
|fix_ampersands
|iriencode
|urlencode[:
safe_chars]
|lower
|upper
|title
|capfirst
|slugify
|ljust:
width
|rjust:
width
|center:
width
|wordwrap
: width
|wordcount
|striptags
|removetags: "p br"
Case sensitive.
|cut: substring
|linebreaks
|linebreaksbr
|linenumbers
|phone2numeric
|truncatechars: count
|truncatewords:
count
|truncatewords_html:
count
|urlize
|urlizetrunc:
length
Template tags
Filters
Built in
Numbers
EscapingText formatting Dates & times
General
Lists
humanize library
i18n library
l10n library
tz library
cache library
comments library
i18n library
static library
tz library
l10n library
staticfiles library
webdesign library
flatpages library
{% cache seconds name [vary_by ...] %} — {% endcache %}
{%
comment_form_target %}
{%
get_comment_count for var as name %}
{%
get_comment_form for var as name %}
{%
get_comment_list for var as name %}
{%
get_comment_permalink comment [format_string] %}
{%
render_comment_form for var %}
{%
render_comment_list for var %}
{%
blocktrans [context context_name]
[with name=value ...] %} — {% endblocktrans %}
{%
blocktrans count name=value [context, with etc.] %} —
{%
plural %} — {% endblocktrans%}
{%
get_available_languages as LANGUAGES %}
{%
get_current_language as LANGUAGE_CODE %}
{%
get_current_language_bidi as LANGUAGE_BIDI %}
{%
get_language_info for "en" as lang %}
lang.code lang.name
lang.name_local lang.bidi
{% get_language_info for list_of_codes as lang %}
{%
trans string [context context_name] [as name] [noop] %}
{%
get_media_prefix [as name] %}
{%
get_static_prefix [as name] %}
{%
static path [as name] %}
{%
get_current_timezone [as TIME_ZONE] %}
{%
localtime on|off %} — {% endlocaltime %}
{%
timezone time_zone_name %} — {% endtimezone %}
{%
localize on|off %} — {% endlocalize %}
{%
static path [as name] %}
{%
lorem [number] [w|p|b] [random] %}
{%
get_flatpages [url_prefix] as name %}