Bird
0
0

Why does this template fragment caching code cause an error?

medium📝 Debug Q7 of 15
Django - Caching
Why does this template fragment caching code cause an error?
{% cache 600 menu %}
  • Item 1
{% endcache %}
ATimeout value 600 is too large
BCache tag cannot wrap <ul> elements
CThe cache key 'menu' is not quoted as a string
DMissing {% endcache %} tag
Step-by-Step Solution
Solution:
  1. Step 1: Check cache key syntax

    Cache keys must be strings quoted with single or double quotes.
  2. Step 2: Verify other parts

    Timeout 600 is valid. Cache can wrap any HTML. The endcache tag is present.
  3. Final Answer:

    The cache key 'menu' is not quoted as a string -> Option C
  4. Quick Check:

    Cache keys must be quoted strings [OK]
Quick Trick: Always quote cache keys as strings [OK]
Common Mistakes:
MISTAKES
  • Leaving cache key unquoted
  • Thinking timeout limits cause errors
  • Believing cache can't wrap HTML tags

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes