0
0
Djangoframework~10 mins

Permission required decorator 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 permission decorator from Django.

Django
from django.contrib.auth.decorators import [1]
Drag options to blanks, or click blank then click option'
Apermission_required
Blogin_required
Cuser_passes_test
Drequire_permission
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'login_required' instead of 'permission_required'.
Trying to import from the wrong module.
2fill in blank
medium

Complete the code to require the 'polls.change_poll' permission on the view.

Django
@permission_required('[1]')
def edit_poll(request):
    pass
Drag options to blanks, or click blank then click option'
Apolls.change_poll
Bpolls.add_poll
Cpolls.delete_poll
Dpolls.view_poll
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' or 'delete' instead of 'change'.
Omitting the app label 'polls'.
3fill in blank
hard

Fix the error in the decorator usage to allow raising 403 error if permission is missing.

Django
@permission_required('polls.change_poll', [1]=True)
def edit_poll(request):
    pass
Drag options to blanks, or click blank then click option'
Araise_error
Bthrow_exception
Craise_exception
Derror_raise
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect argument names like 'raise_error'.
Not passing the argument at all.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Django
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword.startswith('a')
Dword.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of length.
Using wrong condition like startswith.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 3.

Django
{ [1]: [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 3
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase for keys instead of uppercase.
Using wrong condition or value.