Bird
0
0

Which of the following is the correct syntax to cache a Django view for 10 minutes?

easy📝 Syntax Q3 of 15
Django - Caching
Which of the following is the correct syntax to cache a Django view for 10 minutes?
A@cache_page('10m') def my_view(request): pass
B@cache_page(10) def my_view(request): pass
C@cache_page(600) def my_view(request): pass
D@cache_page(timeout=10) def my_view(request): pass
Step-by-Step Solution
Solution:
  1. Step 1: Understand cache_page timeout unit

    The timeout value for @cache_page is in seconds, so 10 minutes = 600 seconds.
  2. Step 2: Check syntax correctness

    @cache_page(600) is correct. @cache_page(10) caches for 10 seconds, '10m' is invalid, and timeout=10 means 10 seconds.
  3. Final Answer:

    @cache_page(600) with 10 minutes timeout -> Option C
  4. Quick Check:

    Timeout in seconds = 600 for 10 minutes [OK]
Quick Trick: Timeout in @cache_page is seconds, 10 min = 600 [OK]
Common Mistakes:
MISTAKES
  • Using minutes or strings instead of seconds
  • Passing timeout as a keyword incorrectly
  • Confusing seconds with minutes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes