I want to count all the elements in a Django template and display them like "how many"
Django's built-in template tags and filters Use {{value | length}}
Example)template.html
<h3>Bookshelf({{ books|length }})</h3>
From the browser Is displayed.
I knew that Rubu on Rails could display it with <% = Objects.all%>, but Django's It took a lot of time to avoid the word built-in tag.
https://docs.djangoproject.com/ja/3.1/ref/templates/builtins/#ref-templates-builtins-filters
Recommended Posts