0
0
Djangoframework~10 mins

Per-view caching in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the decorator needed for per-view caching in Django.

Django
from django.views.decorators.cache import [1]
Drag options to blanks, or click blank then click option'
Acsrf_exempt
Blogin_required
Ccache_page
Drequire_http_methods
Attempts:
3 left
💡 Hint
Common Mistakes
Using decorators unrelated to caching like login_required.
Forgetting to import the decorator before using it.
2fill in blank
medium

Complete the code to cache the view output for 15 minutes using the decorator.

Django
@cache_page([1])
def my_view(request):
    return HttpResponse('Hello World')
Drag options to blanks, or click blank then click option'
A900
B60
C3600
D300
Attempts:
3 left
💡 Hint
Common Mistakes
Using minutes directly instead of seconds.
Using too short or too long timeout values by mistake.
3fill in blank
hard

Fix the error in the decorator usage by completing the code correctly.

Django
@cache_page([1])
def product_list(request):
    # view code here
    pass
Drag options to blanks, or click blank then click option'
A15
B900
C'900'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the timeout as a string instead of an integer.
Passing minutes instead of seconds.
4fill in blank
hard

Fill both blanks to import and apply the cache decorator to a view.

Django
from django.views.decorators.cache import [1]

@[2](60)
def homepage(request):
    return HttpResponse('Welcome!')
Drag options to blanks, or click blank then click option'
Acache_page
Blogin_required
Ccsrf_exempt
Drequire_http_methods
Attempts:
3 left
💡 Hint
Common Mistakes
Importing one decorator but using another.
Using decorators unrelated to caching.
5fill in blank
hard

Fill all three blanks to cache a view with a 5-minute timeout and import the decorator.

Django
from django.views.decorators.cache import [1]

@[2]([3])
def about(request):
    return HttpResponse('About us')
Drag options to blanks, or click blank then click option'
Acache_page
Blogin_required
C300
D900
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong timeout value.
Using a decorator unrelated to caching.