Django - forgot username & password

Django - forgot username & password

Four months ago, I started a django project with the admin module, but soon stopped using . Yesterday, I tried to start it and found that I forgot the admin password.

How to get it back? Let's use the python shell.

Using the Python shell (in terminal)

python manage.py shell

Import module

from django.contrib.auth.models import User

List superuser / all user

# superuser
User.objects.filter(is_superuser=True)

# all user
User.objects.all()

Note down your name and use it in the next step.

Change password

user = User.objects.get(username='name') 
user.set_password('password')
user.save()

Wow, I found my password back ;)