Skip to main content

“Password Reset in Django – Complete Guide”

 Password Reset in Django – Complete Guide



🔐 Introduction

Web applications lo Password Reset feature chala important.
User password marchipothe, easy ga recover chesukovadaniki use avutundi.

Real-time lo:

  • Gmail
  • Facebook
  • Instagram

anni password reset system use chestayi.


⚙️ How Password Reset Works?

👉 Step-by-step flow:

  1. User “Forgot Password” click chestadu
  2. Email enter chestadu
  3. System reset link send chestundi
  4. User link open chestadu
  5. New password set chestadu

👉 Idi secure ga untundi because:

  • Token based verification
  • Time limit untundi

⚙️ Django Password Reset Code

1️⃣ settings.py (EMAIL Setup)

# settings.py

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

👉 Dev lo console lo email link chupistundi
👉 Production lo Gmail SMTP use cheyachu


2️⃣ urls.py

from django.urls import path
from django.contrib.auth import views as auth_views

urlpatterns = [

path('password-reset/',
auth_views.PasswordResetView.as_view(
template_name='registration/password_reset.html'
),
name='password_reset'),

path('password-reset/done/',
auth_views.PasswordResetDoneView.as_view(
template_name='registration/password_reset_done.html'
),
name='password_reset_done'),

path('reset/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(
template_name='registration/password_reset_confirm.html'
),
name='password_reset_confirm'),

path('reset/done/',
auth_views.PasswordResetCompleteView.as_view(
template_name='registration/password_reset_complete.html'
),
name='password_reset_complete'),
]

🎨 Templates

📄 password_reset.html

<h2>Forgot Password</h2>

<form method="POST">
{% csrf_token %}
{{ form.as_p }}

<button type="submit">Send Reset Link</button>
</form>

📄 password_reset_done.html

<h2>Email Sent</h2>
<p>Check your email for reset link 📩</p>

📄 password_reset_confirm.html

<h2>Set New Password</h2>

<form method="POST">
{% csrf_token %}
{{ form.as_p }}

<button type="submit">Change Password</button>
</form>

📄 password_reset_complete.html

<h2>Password Changed Successfully 🎉</h2>
<a href="{% url 'login' %}">Login</a>

🔗 Add Link in Login Page

<a href="{% url 'password_reset' %}">Forgot Password?</a>

🧠 Explanation (Simple)

👉 Django automatically:

  • Token generate chestundi
  • Email send chestundi
  • Password update handle chestundi

👉 Manam:

  • URLs configure chestam
  • Templates create chestam

🔥 Final Flow

👉 User clicks Forgot Password
👉 Email link vastundi
👉 Link open chesi password change chestadu


Comments

  1. it is good and best content i never ever seen

    ReplyDelete

Post a Comment

Popular posts from this blog

Python Day 5 – If Else Conditions

  🐍 Python Day 5 – If Else Conditions 🧠 Introduction 🐍 Python Day 5 – If Else Conditions Ippati varaku manam operators nerchukunnam. I roju manam decision making (If-Else) nerchukundam. 👉 Program lo condition base chesi decisions tiskovadaniki use avutundi 💡 Example: Age 18 kanna ekkuva unte → eligible Lekapothe → not eligible 🔹 Basic If Condition age = 20 if age > 18 : print ( "Eligible" ) 🔹 If-Else Condition age = 16 if age >= 18 : print ( "Eligible" ) else : print ( "Not Eligible" ) 🔹 If-Elif-Else marks = 75 if marks >= 90 : print ( "Grade A" ) elif marks >= 60 : print ( "Grade B" ) else : print ( "Grade C" ) 🧪 Real Example (User Input) age = int ( input ( "Enter your age: " )) if age >= 18 : print ( "You can vote ✅" ) else : print ( "You cannot vote ❌" ) ⚠️ Important Points 👉 Indentation (space) very import...

Python Day 8 – Lists

  🧠 Introduction 🐍 Python Day 8 – Lists Ippati varaku manam functions nerchukunnam. Eroju manam Lists gurinchi nerchukundam. 👉 List ante multiple values ni okesari store cheyadaniki use avutundi 💡 Example: Shopping items list laga 📦 🔹 Create List numbers = [ 1 , 2 , 3 , 4 , 5 ] names = [ "Manju" , "Ravi" , "Kiran" ] 🔹 Access List (Index) print ( numbers [ 0 ]) # 1 print ( names [ 1 ]) # Ravi 👉 Index always 0 nundi start avutundi ⚠️ 🔹 Add Elements numbers . append( 6 ) print ( numbers ) 🔹 Remove Elements numbers . remove( 3 ) print ( numbers ) 🔹 Loop Through List for i in numbers : print ( i ) 🔹 List Length print ( len ( numbers )) 🔹 Slicing print ( numbers [ 1 : 4 ]) 🧪 Real Example marks = [ 80 , 90 , 75 , 60 ] for m in marks : if m >= 75 : print ( "Pass:" , m ) 🎯 Mini Practice names = [ "A" , "B" , "C" ] names . append( "D...