Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q6 of 15
Django - Caching
What is wrong with this code snippet?
from django.views.decorators.cache import cache_page

@cache_page('300')
def my_view(request):
    return HttpResponse('Hello')
ATimeout should be an integer, not a string
BMissing import for HttpResponse
CDecorator must be applied inside the function
DFunction must be async for caching
Step-by-Step Solution
Solution:
  1. Step 1: Check cache_page timeout type

    The timeout argument must be an integer number of seconds, not a string.
  2. Step 2: Verify other code parts

    HttpResponse import is missing but not shown; decorator outside function is correct; async not required.
  3. Final Answer:

    Timeout should be an integer, not a string -> Option A
  4. Quick Check:

    Timeout must be int, not string [OK]
Quick Trick: Timeout in @cache_page must be integer seconds [OK]
Common Mistakes:
MISTAKES
  • Passing timeout as string
  • Thinking decorator must be inside function
  • Assuming async needed for caching

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes