Last active
March 3, 2026 09:53
-
-
Save kevinhooke/5e03ce43f1f004a37a4f5a3a6763e841 to your computer and use it in GitHub Desktop.
Django view template notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% 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