Changing Super User Password in Django

There was a time when I learned how to create a blog using Django, but I forgot the admin password. What should I do? One way to reset your password is by using the Django shell. The Django shell is an interactive Python environment that provides access to models and settings through the command line.

Here’s how to reset your password:

  • Open a terminal and navigate to the root folder containing the manage.py file.
  • Type the command to open the Django shell: python manage.py shell
  • Once you’re in the shell, the prompt will display three greater-than signs (>>>) indicating that you’re successfully logged in.
  • Import the User model from Django.
  • Retrieve your user record using your username (for example, “admin”).
  • Set a new password for that username.
  • Save all the updates to the database.

That’s it! Now you can try logging in with your new password.

Leave a Comment