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

Django ante enti? (Beginner Friendly Telugu Guide)

  Introduction Meeru web development start cheyyali anukuntunnara? Leka backend development nerchukovali anukuntunnara? Appudu meeru tappakunda vinnadi oka peru 👉 Django Ee article lo manam simple ga, clear ga ardham ayyela chuddam — Django ante enti, enduku use chestaru, ela start cheyyali.

Django Templates & HTML Rendering (Complete Guide Telugu)

  Introduction Previous article lo manam Views & URLs chusam. Ipudu next important concept 👉 Templates & HTML Rendering Django lo dynamic HTML pages ela create cheyyalo ee article lo nerchukundam 🔥 🧠 Templates ante enti? 👉 Template ante HTML file "T emplate ante HTML file matrame kaadu, Django lo dynamic content ni display cheyadaniki use chestam. Example ga, database lo unna blog posts ni HTML page lo chupinchadaniki templates use avutayi. " But special enti ante: 👉 Dynamic data display cheyyachu (Python data → HTML lo show) 📁 Templates folder create cheyyadam Mee app lo templates ane folder create cheyandi: myapp/ templates/ index.html ⚙️ settings.py lo config cheyyali settings.py open cheyandi: TEMPLATES = [ { 'DIRS': [], ... }, ] 👉 Usually app templates automatic ga detect chestundi 💻 Simple HTML Template index.html : <!DOCTYPE html> <html> <head> <title>Django Page</title> ...

Django Views & URLs (Complete Guide Telugu)

Introduction Previous article lo manam Django project create chesam. Ipudu chuddam 👉 user request vachinappudu Django ela respond avthundi? Django lo Views & URLs anevi chala important concepts 🔥 🧠 Simple ga ardham: 👉 URL = address 👉 View = action (logic) User URL enter chesthe → View execute avthundi 🔗 URLs ante enti? Example: http://127.0.0.1:8000/about/ http://127.0.0.1:8000/contact/ 👉 /about/ , /contact/ ni URLs antaru Django lo ee URLs ni urls.py file lo define chestam ⚙️ urls.py Example from django.urls import path from . import views urlpatterns = [ path('about/', views.about_view), ] 👉 Ikkada: 'about/' → URL about_view → View function ⚡ Views ante enti? 👉 View ante Python function User request vachinappudu: 👉 View function run avthundi 👉 Response return chestundi 💻 Simple View Example from django.http import HttpResponse def about_view(request): return HttpResponse("Hello from About Page") 👉 Browser lo /about/ open ches...