DEV Community

Samuel Raphael
Samuel Raphael

Posted on

How I Changed My Django App Admin Password

I know most of all have fallen prey to setting a ridiculously hard password to our admin panels, saving them somewhere and loosing the password due to forgetfulness, or one of the other many reasons we lose our passwords.

This happened to me while working through a Django tutorial and I just want to document how I was able to solve it.

1) Access your python shell using:

python manage.py shell
Enter fullscreen mode Exit fullscreen mode

This little code snippet will bring up your python shell development.

2) Next thing we will do is to get the lists of users and this can by done by:

a: Import Users from Django auth:

from django.contrib.auth.models import User
Enter fullscreen mode Exit fullscreen mode

b: Assign Users objects to a variable and print it:

users = User.objects.all()
print users
Enter fullscreen mode Exit fullscreen mode

This prints out the total users in your application, and you can select which is your admin. Generally though, the admin user is often always the first user created.

3) Select the ‘id’ of the admin user:

user = users[0]
Enter fullscreen mode Exit fullscreen mode

4) Set a new password for the user:

user.set_password('the password')
Enter fullscreen mode Exit fullscreen mode

5) Save the new password:

user.save()
Enter fullscreen mode Exit fullscreen mode

Top comments (4)

Collapse
 
cyberorgnizm profile image
Adole Samuel

Thanks, I had this issue once, I had to delete the project and start again... Thanks for showing an easier way for fixing this.

Collapse
 
ghost profile image
Ghost

When you encounter any problem while using your Lexmark printer, avail support by dialing the Lexmark printer support toll-free number. The customer support service can be reached out for all technical issues.

Click This Link :- printer-customer-support.com/lexmark/

Collapse
 
showboxdownload profile image
showbox download

well thanks , i was having trouble with the same
crumbles.co/showbox-apk-download/

Collapse
 
mbaechtold profile image
Martin Bächtold

There is convenient management command for that:

python manage.py changepassword