Performance: Template variables with double braces
This affects the rendering speed of HTML pages by how Django processes template variables before sending HTML to the browser.
{% for item in items %}
<p>{{ item.cached_property }}</p>
{% endfor %}{% for item in items %}
<p>{{ item.get_expensive_property }}</p>
{% endfor %}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using complex method calls in {{ }} inside loops | N/A (server-side) | N/A | Delays initial paint | [X] Bad |
| Using simple variables or cached data in {{ }} | N/A (server-side) | N/A | Faster initial paint | [OK] Good |
{{ variable }} do in a Django template?user_name in a Django template?{'count': 5} to the template, what will be rendered by this template code?<p>Total items: {{ count }}</p>{'user': {'name': 'Anna'}}?<p>User: {{ user.name }}</p>{'user': {'first_name': 'John', 'last_name': 'Doe'}}. Which template code correctly shows "John Doe" using double braces?Pass the test and this pattern moves unknown