0
0
Djangoframework~10 mins

Template permission checks 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 check if the user has permission to add an object in the template.

Django
{% if user.has_perm('[1]') %}You can add this item.{% endif %}
Drag options to blanks, or click blank then click option'
Aapp.delete_item
Bapp.add_item
Capp.change_item
Dapp.view_item
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong action like 'delete' or 'change' instead of 'add'.
Forgetting to include the app label.
2fill in blank
medium

Complete the code to check if the user has permission to delete an object in the template.

Django
{% if user.has_perm('[1]') %}You can delete this item.{% endif %}
Drag options to blanks, or click blank then click option'
Aapp.delete_item
Bapp.view_item
Capp.add_item
Dapp.change_item
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'view' or 'add' instead of 'delete'.
Omitting the app label.
3fill in blank
hard

Fix the error in the template code to correctly check if the user can change an object.

Django
{% if user.[1]('app.change_item') %}You can edit this item.{% endif %}
Drag options to blanks, or click blank then click option'
Acan_perm
Bhas_permission
Ccheck_perm
Dhas_perm
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like 'has_permission' or 'check_perm'.
Misspelling the method name.
4fill in blank
hard

Fill both blanks to check if the user has permission to view an object and display a message.

Django
{% if user.[1]('[2]') %}You can view this item.{% endif %}
Drag options to blanks, or click blank then click option'
Ahas_perm
Bhas_permission
Capp.view_item
Dapp.change_item
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names.
Using wrong permission strings like 'change' instead of 'view'.
5fill in blank
hard

Fill all three blanks to check if the user has permission to add an object and show a message.

Django
{% if user.[1]('[2]') %}[3]{% endif %}
Drag options to blanks, or click blank then click option'
Ahas_perm
Bapp.add_item
CYou have permission to add this item.
DYou can delete this item.
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong permission strings.
Displaying the wrong message.