Imagine a Django app where users can view and edit data. What is the main reason to use authorization?
Think about keeping data safe and limiting access.
Authorization ensures users only do what they are allowed to do, protecting data and app integrity.
Consider a Django view that shows user profiles but has no authorization. What is the likely outcome?
Think about what happens when no rules limit access.
Without authorization, users can access data they shouldn't, risking privacy and security.
Given this Django view code, what will be the HTTP response status if a user without 'can_edit' permission tries to access it?
from django.contrib.auth.decorators import permission_required from django.http import HttpResponse @permission_required('app.can_edit') def edit_view(request): return HttpResponse('Edit page')
What does the decorator do when permission is missing?
The decorator returns 403 Forbidden if the user lacks the required permission.
Choose the code snippet that properly restricts a view to staff users.
Look for the built-in decorator designed for staff access.
@staff_member_required is the standard decorator that restricts access to staff users and redirects others.
Review this Django view code. Why does it allow users without 'can_view' permission to access the page?
def view_page(request): if request.user.has_perm('app.can_view'): pass return HttpResponse('Page content')
Check where the return statement is placed in relation to the permission check.
The return statement is outside the if block, so the page always returns content regardless of permission.