Kim Majali wrote on 07/06/2022
{% if request.method == "GET" %} Get {% else%} post {% endif %}
{% if request.GET.my_var %}
Read moreKim Majali wrote on 07/06/2022
{% load humanize %}
{{ my_num|intcomma }}
apnumber
1
becomes one
.2
becomes two
.10
becomes 10
.intcomma
4500
becomes 4,500
.4500.2
becomes 4,500.2
.45000
becomes 45,000
.450000
becomes 450,000
.4500000
becomes 4,500,000
.'de'
language:
45000
becomes '45.000'
.450000
becomes '450.000'
.intword
1.0
as a singular phrase and all other numeric values as plural, this may be incorrect for some languages. Works best for numbers over 1 million.
Examples:
1000000
becomes 1.0 million
.1200000
becomes 1.2 million
.1200000000
becomes 1.2 billion
.-1200000000
becomes -1.2 billion
.'de'
language:
1000000
becomes '1,0 Million'
.1200000
becomes '1,2 Millionen'
.1200000000
becomes '1,2 Milliarden'
.-1200000000
becomes '-1,2 Milliarden'
.naturalday
date
tag.
Examples (when ‘today’ is 17 Feb 2007):
16 Feb 2007
becomes yesterday
.17 Feb 2007
becomes today
.18 Feb 2007
becomes tomorrow
.DATE_FORMAT
setting if no argument is given.naturaltime
timesince
format if the value is more than a day old. In case the datetime value is in the future the return value will automatically use an appropriate phrase.
Examples (when ‘now’ is 17 Feb 2007 16:30:00):
17 Feb 2007 16:30:00
becomes now
.17 Feb 2007 16:29:31
becomes 29 seconds ago
.17 Feb 2007 16:29:00
becomes a minute ago
.17 Feb 2007 16:25:35
becomes 4 minutes ago
.17 Feb 2007 15:30:29
becomes 59 minutes ago
.17 Feb 2007 15:30:01
becomes 59 minutes ago
.17 Feb 2007 15:30:00
becomes an hour ago
.17 Feb 2007 13:31:29
becomes 2 hours ago
.16 Feb 2007 13:31:29
becomes 1 day, 2 hours ago
.16 Feb 2007 13:30:01
becomes 1 day, 2 hours ago
.16 Feb 2007 13:30:00
becomes 1 day, 3 hours ago
.17 Feb 2007 16:30:30
becomes 30 seconds from now
.17 Feb 2007 16:30:29
becomes 29 seconds from now
.17 Feb 2007 16:31:00
becomes a minute from now
.17 Feb 2007 16:34:35
becomes 4 minutes from now
.17 Feb 2007 17:30:29
becomes an hour from now
.17 Feb 2007 18:31:29
becomes 2 hours from now
.18 Feb 2007 16:31:29
becomes 1 day from now
.26 Feb 2007 18:31:29
becomes 1 week, 2 days from now
.ordinal
1
becomes 1st
.2
becomes 2nd
.3
becomes 3rd
.Kim Majali wrote on 06/06/2022
{% if x > 5 %} # You need some spaces
Read moreKim Majali wrote on 06/06/2022
{% if "bc" in "abcdef" %}
This appears since "bc" is a substring of "abcdef"
{% endif %}
{% if "hello" in greetings %}
If greetings is a list or set, one element of which is the string
"hello", this will appear.
{% endif %}
{% if user in users %}
If users is a QuerySet, this will appear if user is an
instance that belongs to the QuerySet.
{% endif %}
{% if somevar is True %}
This appears if and only if somevar is True.
{% endif %}
{% if somevar is None %}
This appears if somevar is None, or if somevar is not found in the context.
{% endif %}
{% if somevar is not True %}
This appears if somevar is not True, or if somevar is not found in the
context.
{% endif %}
{% if somevar is not None %}
This appears if and only if somevar is not None.
{% endif %}
{% if messages|length >= 100 %}
You have lots of messages today!
{% endif %}
{{ value|linebreaks }}
{{ value|linebreaksbr }}
{{ value|linenumbers }}
Read moreTopics: Templates