Django Tutorial 6 - User Authentication Part 1 - Hacked Existence -
from django.contrib.auth import views as auth_views from django.urls import path urlpatterns = [ path('login/', auth_views.LoginView.as_view(), name='login'), ] Use code with caution. Copied to clipboard 2. Create the Login Template
: The core of the authentication system containing fields like username, password, and email. from django
: Verifies that a user is who they claim to be. : Verifies that a user is who they claim to be
: Determines what an authenticated user is allowed to do. Copied to clipboard After a successful login, Django
from django.contrib.auth.decorators import login_required from django.shortcuts import render @login_required def secret_page(request): return render(request, 'secret.html') Use code with caution. Copied to clipboard
After a successful login, Django needs to know where to send the user. You can define this in your settings.py file.
INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.contenttypes', # ... other apps ] Use code with caution. Copied to clipboard 📝 Step 2: Set Up the Login View