obvioustest=# \c [yourdatabasename]
obvioustest=# \x
obvioustest=# select * from auth_user;
-[ RECORD 1 ]+-------------
id | 1
is_superuser | f
is_staff | f
...
python manage.py shell
from django.contrib.auth.models import User
usrs = User.objects.filter(is_superuser=True)
#identify the user
your_user = usrs.filter(username="yourusername")[0]
#youruser = usrs.get(username="yourusername")
#then set the password
from django.contrib.auth import get_user_model
super_users = get_user_model().objects.filter(is_superuser=True)
#proceed to get identify your user
# and set their user password
Python 3.7.2 (default, Mar 27 2019, 08:44:46)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
然后你会想要以下内容:
>>> from django.contrib.auth import get_user_model
>>> User = get_user_model()
>>> user = User.objects.get(username='admin@hug.com')
>>> user.set_password('new password')
>>> user.save()
>>> exit()