Django Admin Password forgotten

I created admin user and added some other users to build an authentication form login form. I then loged out the ADMIN and tried to login but i forgot the password. I need to reset my admin password . Could you plz help me how to figure it out.

Open a shell instance:
python manage.py shell

Grab your User

my_user = YourUserModel.objects.filter(email="blabla@example.com").first()
my_user.set_password("NewPassword")
my_user.save()

There’s a management command changepassword that allows you to reset any password from the command line.

I run this code and it says “NameError: name ‘YourUserModel’ is not defined”

It says changepassword is not recognised.

Please provide the exact command line you used to try running it, along with the complete error message that was returned.

1 Like
C:\Users\hp\Downloads\WEB DEV WITH PYTHON AND JAVASCRIPT\airline>django-admin changepassword Nooh
No Django settings specified.
Unknown command: 'changepassword'
Type 'django-admin help' for usage.

C:\Users\hp\Downloads\WEB DEV WITH PYTHON AND JAVASCRIPT\airline>

This is the complete code u run.

You would run this command as python manage.py changepassword. See the docs at the top of that page.

1 Like

Thank you sir. I resolved the error. You are right i should type python instead of py.

In my case, the manager user was called ‘admin’, so I type in the line command:
‘python manage.py changepassword admin’
Then it ask me a new password, and then again the confirmation.
All OK.
Thank you!