Django Template Built-In Filters Django.How

Author avatar 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 %}

 

Format Text

linebreaks Replaces line breaks in plain text with appropriate HTML; a single newline becomes
and a new line followed by a blank line becomes

{{ value|linebreaks }}

 

Linebreaksbr Converts all newlines in a piece of plain text to

{{ value|linebreaksbr }}

 

Linenumbers Displays text with line numbers.

{{ value|linenumbers }}

 

CRUDgen Django CRUD generator