How to reset the password of Django admin user

Django is a free and open-source web framework, written in Python, which follows the model-view-template architectural pattern.

This article explains the detailed steps to reset the password of Django admin user.

Step1: Login to the server via ssh

Step2: Change the location to the virtual environment folder.

#cd virtual-environment-path

Where virtual-environment-path is the path to the location of the virtual environment.

Step3: Activate the python virtual environment.

#source bin/activate

Step3: Enter Django shell

#python manage.py shell

Step4: Import the User model

>from django.contrib.auth.models import User

Step5: List the users

>users = User.objects.all()
>print (users)

Step6: Select the admin user.

>user = users[0]

Step7: Update the new password

>user.set_password('password')

Here we need to update 'password' with the new password that need to be updated.

Step8: Save the data

>user.save()

That's all...

Leave a Reply

Your email address will not be published. Required fields are marked *