Bird
0
0

Which of the following is the correct way to apply per-view caching with a 5-minute timeout in Django?

easy📝 Syntax Q12 of 15
Django - Caching
Which of the following is the correct way to apply per-view caching with a 5-minute timeout in Django?
A@cache_page('300') def my_view(request): pass
B@cache_page(5) def my_view(request): pass
C@cache_page(timeout=5) def my_view(request): pass
D@cache_page(300) def my_view(request): pass
Step-by-Step Solution
Solution:
  1. Step 1: Understand the timeout parameter

    The timeout is in seconds, so 5 minutes = 300 seconds.
  2. Step 2: Check correct syntax for @cache_page

    The decorator takes an integer timeout in seconds without quotes.
  3. Final Answer:

    @cache_page(300)\ndef my_view(request):\n pass -> Option D
  4. Quick Check:

    Timeout in seconds, no quotes = @cache_page(300) def my_view(request): pass [OK]
Quick Trick: Timeout is seconds as integer, no quotes [OK]
Common Mistakes:
MISTAKES
  • Using string '300' instead of integer
  • Passing timeout as minutes instead of seconds
  • Using keyword argument timeout incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes