Bird
0
0

Which decorator is used in Django to apply per-view caching?

easy📝 Conceptual Q2 of 15
Django - Caching
Which decorator is used in Django to apply per-view caching?
A@login_required
B@cache_page
C@csrf_exempt
D@transaction.atomic
Step-by-Step Solution
Solution:
  1. Step 1: Recall Django caching decorators

    Django provides @cache_page to cache the output of a view for a set time.
  2. Step 2: Match the decorator to caching

    @login_required is for authentication, @csrf_exempt for security, @transaction.atomic for DB transactions, so only @cache_page fits caching.
  3. Final Answer:

    @cache_page -> Option B
  4. Quick Check:

    Per-view caching decorator = @cache_page [OK]
Quick Trick: Use @cache_page to cache a view's response in Django [OK]
Common Mistakes:
MISTAKES
  • Mixing caching with authentication decorators
  • Using security decorators for caching
  • Confusing transaction decorators with caching

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes