Bird
0
0

Identify the error in this template fragment caching usage:

medium📝 Debug Q14 of 15
Django - Caching
Identify the error in this template fragment caching usage:
{% cache 'sidebar' 300 %}
Sidebar content
{% endcache %}
AThe timeout and key order is reversed; timeout must come first
BMissing closing tag {% endcache %}
CThe cache key must be an integer, not a string
DCache tag cannot wrap HTML elements
Step-by-Step Solution
Solution:
  1. Step 1: Check the order of arguments in the cache tag

    The correct order is timeout (integer) first, then cache key (string).
  2. Step 2: Identify the mistake in the given code

    The code uses 'sidebar' first and 300 second, which is reversed.
  3. Final Answer:

    The timeout and key order is reversed; timeout must come first -> Option A
  4. Quick Check:

    Timeout first, key second in cache tag [OK]
Quick Trick: Timeout always before key in cache tag [OK]
Common Mistakes:
MISTAKES
  • Swapping timeout and key order
  • Forgetting to close cache tag
  • Thinking cache tag can't wrap HTML

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes