Complete the code to import the login_required decorator from Django.
from django.contrib.auth.decorators import [1]
The login_required decorator is imported from django.contrib.auth.decorators to restrict access to views.
Complete the code to apply the login_required decorator to a Django view function.
@[1] def dashboard(request): return render(request, 'dashboard.html')
The @login_required decorator is used above the view function to restrict access to logged-in users only.
Fix the error in the code by completing the decorator usage correctly.
from django.contrib.auth.decorators import login_required @login_[1] def profile(request): return render(request, 'profile.html')
The correct decorator name is login_required. The code must have @login_required exactly.
Fill both blanks to complete the code that redirects unauthorized users to a custom login page.
@login_required(login_url='[1]') def settings(request): return render(request, '[2]')
The login_url parameter sets a custom login page URL. The view renders the 'settings.html' template.
Fill all three blanks to create a class-based view that requires login using the login_required decorator.
from django.utils.decorators import method_decorator from django.views import View @method_decorator(login_required, name='[1]') class AccountView(View): def [2](self, request): return render(request, '[3]')
The login_required decorator is applied to the dispatch method to protect all HTTP methods. The view defines a get method rendering 'account.html'.