Change password of a user in Django

Aug 1, 2018

Start by opening the Django shell from your terminal

> python manage.py shell

Then inside the Django shell, first get hold of that user object, then change the password and save.

from django.contrib.auth.models import User
u = User.objects.get(pk=id_of_desired_user)
u.set_password('new password')
u.save()

The user is looked up by primary key in this example. But the lookup can be based on user name, email or any other attribute.