TS-10 Django Authentication
TS-10 Django Authentication
Authentication
Authorization, Authentication,
Login & Registration
User Authentication
Implementing Login
and Authorization
System
Implementing
Practical Tasks
Registration System
User Authentication:
Verifying the identity of a
Introducti user (e.g., username and
User Authorization:
password).
on to Determining what an
Django authenticated user
can do provides
Django (permissions,
built-in
Authentic groups, etc.).
support for user
ation authentication with
customizable views,
models, and forms.
User submits
login form with
credentials.
Django
Authenti authenticates
the user by
cation verifying
User session is
credentials.
Workflow created upon
successful
in Django authentication.
Permissions are
checked for
accessing
different views.
Built-in User Model
Attributes:
User username
password
Model email
• first_name, last_name
Up
Authentic
Configure Settings:
ation in
• LOGIN_REDIRECT_URL = '/'
Django • LOGOUT_REDIRECT_URL =
'/'
Create Login
View:
• Use Django's built-in
LoginView.
Implemen Create a Login
ting Login Template
• Simple HTML form for
username and
Update URLs
password.
to
include login.
Task 1: Login System (30
Mins)
• Create a login form using Django's LoginView.
• Update URL configurations to include login and
logout paths.
• Create a simple login template to display the login
form.
Create a
Registration Form:
• Use Django's
Implemen UserCreationForm.
Create a View for
ting Registration:
Registrati • Handle form submission
on and user creation.
Update URL
Configurations:
• Add a path for
registration.
Registra
tion
VIEW
Example
* view.py
Task 2: Registration System
(30 Mins)
• Create a registration view using UserCreationForm.
• Add registration URL to your URL configurations.
• Create a registration template to display the
registration form.
Built-in Permission
System:
Authoriza • is_authenticated:
tion with Checks if the user is
Permissio logged in.
•Assign
is_staff, is_superuser:
ns
Permissions
Special user statuses.
•using
Custom Django
permissions
can be added to
Admin
models. or code.
Task 3: Implementing
Permissions (15 Mins)
• Add a custom permission to a model.
• Use a view decorator to restrict access based on the
permission.
• Test the permission by logging in with different user
roles.
recap
Login and
Registration
Authorizatio
Authenticati Systems:
n: Managing
on: Verifying Implemented
user
user identity. using built-in
permissions.
Django views
and forms.
Django
Additiona Documentation:
https://docs.djangopro
l ject.com/en/stable/top
ics/auth/