Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Django
  • Views
  • Model
  • Template
  • Forms
  • Jinja
  • Python SQLite
  • Flask
  • Json
  • Postman
  • Interview Ques
  • MongoDB
  • Python MongoDB
  • Python Database
  • ReactJS
  • Vue.js
Open In App
Next Article:
How to Override CSS in Django Admin?
Next article icon

How to Reset Django Admin Password?

Last Updated : 17 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Forgetting or needing to reset the admin password in Django is a common issue that can be resolved in a few easy steps. Django provides several ways to reset the admin password, depending on the situation. In this article, we'll explore multiple methods to help you recover or reset the password for your Django admin account.

Reset Password via Django Shell

One of the easiest ways to reset the Django admin password is by using the Django shell. The Django shell is a Python shell that interacts with your project’s models and database. This method is quick and does not require you to restart the server.

Open the Django Shell

In your terminal, navigate to your Django project directory and run the following command:

python manage.py shell

Import the User Model

Once inside the shell, import the User model from django.contrib.auth.models:

from django.contrib.auth.models import User

Find the Admin User

Retrieve the admin user by their username or email. For example, to find the admin by username:

user = User.objects.get(username='admin')

Replace 'admin' with the username of the admin account, you need to reset it.

Set a New Password

Now, use the set_password() method to reset the admin password:

user.set_password('new_password')
user.save()

Replace 'new_password' with your desired password. Make sure to save the user after resetting the password.

Exit the Shell

Once you’ve set the new password, type exit() to close the Django shell.

Your admin password has now been reset, and you can log in with the new credentials.

Reset Password Using the changepassword Command

Django also provides a built-in management command called changepassword, which is another simple way to reset the password for any user account, including admin accounts.

Run the changepassword Command

In your terminal, use the following command:

python manage.py changepassword admin

Replace admin with the username of the admin account.

Enter a New Password

After running the command, you’ll be prompted to enter a new password for the user:

Changing password for user 'admin'
Password: ********
Password (again): ********

Password Successfully Changed

After confirming the new password, you’ll receive a message saying that the password has been successfully changed. You can now log in to the Django admin interface using the new password.

Conclusion

Resetting a Django admin password can be done quickly and easily using the Django shell, management commands, or through the admin interface. Each method offers a simple solution depending on your access to the system.


Next Article
How to Override CSS in Django Admin?
author
sagar99
Improve
Article Tags :
  • Python
  • Django
  • Python Django
Practice Tags :
  • python

Similar Reads

  • How to Reset Windows Admin Password?
    If you forgot your Windows administrator password, you might be locked out of your computer and unable to access your files and settings. However, there are some ways to reset your password without losing your data or reinstalling Windows. In this article, we will show you how to reset your Windows
    5 min read
  • How to Reset Password for Azure Database
    Microsoft Azure's Azure Database provides cloud-based database solutions for all types of data management requirements. Users don't need to worry about infrastructure upkeep while creating, scaling, and managing databases thanks to alternatives like SQL databases and Azure Database for MySQL. This p
    4 min read
  • How to Override CSS in Django Admin?
    Django's admin interface is a powerful tool for managing application data. It comes with a default styling that may not always fit the visual identity of your project. Customizing the admin interface can help create a more cohesive user experience. In this article, we'll walk you through the process
    3 min read
  • How to Recover an Apple ID Password?
    Forgetting your Apple ID password can be a frustrating experience for users, especially considering how integral the Apple ID is to accessing various services like iCloud, the App Store, and Apple Music. Fortunately, recovering your Apple ID password is a straightforward process. This article will w
    6 min read
  • How to create a Django project?
    Dive into the world of web development with Python by exploring the versatile Django framework. Django is a go-to for many developers due to its popularity, open-source license, and robust security features. It enables fast and efficient project development. In this tutorial, we will guide you throu
    5 min read
  • How to Change Computer Password?
    There are only a few people who don't use passwords on their Computer. User password is the most basic security check that helps you restrict unauthorized access to your computer. It's a good practice to change your passwords in a short span that helps your password to be healthy. By the end of this
    3 min read
  • How to Reset Forgotten Password on Kali Linux
    Kali Linux is a Linux distribution used in the Cybersecurity domain. It is maintained and funded by Offensive Security. Kali Linux is Debian based and it uses the Debian repository for most of its packages. This Linux distribution is designed for digital forensics and penetration testing. It has 600
    4 min read
  • How to Change the Oracle Database Password?
    Changing the password of an Oracle Database is an essential administrative task that can be done through two main methods such as using the ALTER USER command or the PASSWORD command in the command prompt. Both methods are straightforward and offer flexibility depending on our preference for databas
    3 min read
  • How To Add Unit Testing to Django Project
    Unit testing is the practice of testing individual components or units of code in isolation to ensure they function correctly. In the context of Django, units typically refer to functions, methods, or classes within your project. Unit tests are crucial for detecting and preventing bugs early in deve
    4 min read
  • How to create superuser in Django?
    Django comes with a built-in admin panel that allows developers to manage the database, users and other models efficiently. This eliminates the need for creating a separate admin interface from scratch. To access and manage the Django Admin panel, we need to create a superuser i.e. a user with full
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences