Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
Last active March 3, 2026 09:53
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"
Exposing an Enum to a view template:
- return the Enum in context for the view:
return render(
request,
"example/example_template.html",
{
"ExampleStatus": ExampleStatus,
},
)
- can then refernece ExampleStatus in {% if %} comparisons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment