Complete the code to import the Django authorization decorator.
from django.contrib.auth.decorators import [1]
The login_required decorator ensures only logged-in users can access a view.
Complete the code to protect a view so only logged-in users can access it.
@[1] def dashboard(request): return render(request, 'dashboard.html')
The login_required decorator is used to restrict access to authenticated users.
Fix the error in the code to check if a user has permission to add a post.
if request.user.has_perm('[1]'): # allow adding post pass
The permission string format is '
Fill both blanks to restrict a view to users with 'change_article' permission and redirect unauthorized users.
@permission_required('[1]', login_url='[2]') def edit_article(request): return render(request, 'edit.html')
The permission_required decorator takes the permission string and a login URL to redirect unauthorized users.
Fill all three blanks to create a dictionary comprehension that maps usernames to their email if the user is active.
user_emails = {user.[1]: user.[2] for user in users if user.[3]This comprehension creates a dictionary of usernames to emails only for active users.