Django Templates Flashcards
6 cards from real Django practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Django Templates flashcards as text
What does `{{ value|default:'N/A' }}` do in a Django template?
Answer: Outputs 'N/A' if value is False, None, or empty
The default filter outputs the given fallback string if the variable evaluates to False, None, or an empty string.
Which Django template tag is used for conditional rendering?
Answer: {% if condition %}...{% endif %}
The {% if %} tag evaluates a condition and renders its contents only when the condition is truthy; it supports {% elif %} and {% else %} branches.
What does the `{% url 'viewname' %}` template tag do?
Answer: Generates a URL for the named view, reversing the URL pattern
{% url %} calls Django's reverse() function at template render time to produce the correct URL for a named view, avoiding hardcoded paths.
How does Django's template inheritance handle content in a child template outside of blocks?
Answer: It ignores all content outside block tags in child templates
When using template inheritance with {% extends %}, only content inside {% block %} tags is rendered; everything else in the child template is silently ignored.
Which filter formats a number with commas as thousands separators in Django templates?
Answer: intcomma
The intcomma filter from django.contrib.humanize formats integers with commas, e.g., 1000000 becomes 1,000,000; requires {% load humanize %}.
What does `{{ value|truncatewords:10 }}` do in a Django template?
Answer: Truncates the string to 10 words and appends an ellipsis
The truncatewords filter cuts off the string after the given number of words and appends '...' to indicate truncation.
Written and edited by Nathan Beja, founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy