Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
Created November 25, 2025 09:42
Show Gist options
  • Select an option

  • Save kevinhooke/5e03ce43f1f004a37a4f5a3a6763e841 to your computer and use it in GitHub Desktop.

Select an option

Save kevinhooke/5e03ce43f1f004a37a4f5a3a6763e841 to your computer and use it in GitHub Desktop.
Django view template notes
{% expression %}
{{ output_value_in_context }}
{% for item in items %}
{{ item }}
{% endfor %}
{% if item %}
output something
{% else %}
something else
{% endif %}
Conditional dislay:
{{ value_in_context:default_if_none:"something else" }}
Note no space between default_if_none:"something else" - if you add spaces you get error:
"default_if_none requires 2 arguments, 1 provided"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment