Authentication
Use Django’s auth views, sessions and permission checks.
What you will be able to do
- Use the built-in LoginView and LogoutView.
- Protect views with login_required.
- Check object permissions, not just login state.
- Never store plaintext passwords.
In plain English
Django ships authentication: user model, password hashing, sessions and login views. Use the built-in views first and add permission checks with login_required or LoginRequiredMixin. Do not build password storage yourself.
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
@login_required
def dashboard(request):
return render(request, 'dashboard.html')Your turn
EasyProtect a view
Add login_required to a view function named dashboard.
PYTHON · starter
def dashboard(request):Check your understanding before moving on.
Knowledge checkQuestion 1
Which decorator requires a signed-in user for a view?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.