Challenge - 5 Problems
Template Permission Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What will this Django template render?
Given the following Django template snippet, what will be rendered if the user has the 'app.view_item' permission?
{% if perms.app.view_item %}You can view this item.{% else %}Access denied.{% endif %}Django
{% if perms.app.view_item %}You can view this item.{% else %}Access denied.{% endif %}Attempts:
2 left
💡 Hint
The 'perms' variable in Django templates checks user permissions.
✗ Incorrect
The 'perms' context variable allows checking if the user has a specific permission. If the user has 'app.view_item', the first block renders.
📝 Syntax
intermediate1:30remaining
Identify the syntax error in this permission check
What is wrong with this Django template code?
{% if perms.app.view_item == True %}Allowed{% else %}Denied{% endif %}Django
{% if perms.app.view_item == True %}Allowed{% else %}Denied{% endif %}Attempts:
2 left
💡 Hint
Django template if tags do not require explicit boolean comparisons.
✗ Incorrect
In Django templates, 'perms.app.view_item' already evaluates to True or False. Using '== True' is not a syntax error but unnecessary. The correct style is without '== True'.
🔧 Debug
advanced2:00remaining
Why does this permission check always fail?
Consider this Django template snippet:
The user has the permission 'app.view_item', but the template always renders 'Hide'. Why?
{% if perms.app.view_item %}Show{% else %}Hide{% endif %}The user has the permission 'app.view_item', but the template always renders 'Hide'. Why?
Django
{% if perms.app.view_item %}Show{% else %}Hide{% endif %}Attempts:
2 left
💡 Hint
Check if the user context is available in the template.
✗ Incorrect
If the user is not passed to the template context or the authentication context processor is missing, 'perms' will not have permission info, causing the check to fail.
❓ state_output
advanced2:00remaining
What is the output of this permission loop?
Given this Django template code:
What will be the output if the user has permissions 'app.view_item' and 'app.change_item'?
{% for perm in perms.app %}{{ perm }} {% endfor %}What will be the output if the user has permissions 'app.view_item' and 'app.change_item'?
Django
{% for perm in perms.app %}{{ perm }} {% endfor %}Attempts:
2 left
💡 Hint
'perms.app' is not a list but a permission checker object.
✗ Incorrect
'perms.app' is not iterable in Django templates. It is a special object to check permissions, so looping over it causes an error.
🧠 Conceptual
expert2:30remaining
Which template code correctly checks multiple permissions?
You want to show a message only if the user has both 'app.view_item' and 'app.change_item' permissions. Which Django template snippet does this correctly?
Attempts:
2 left
💡 Hint
Use 'and' to combine conditions in Django templates.
✗ Incorrect
Django templates support 'and' for combining conditions. Option B uses 'and' correctly. Option B is nested but more complex. Option B uses 'or' which is incorrect. Option B uses '&' which is invalid in templates.