5👍
✅
From the docs:
set_password(raw_password):
Sets the user’s password to the given raw string, taking care of the password hashing.
It sets the password for you, and then returns None
, so don’t assign it back to user.password
. In other words, just do:
admin.username = 'admin'
admin.set_password('admin')
admin.save()
4👍
.set_password()
already sets the password of the given user, so doesn’t return anything. Thus, you should just do:
>>> admin.set_password('admin')
>>> admin.save()
Assuming you want to create a user that will have permission for everything, why don’t you use .create_superuser()
instead:
>>> User.objects.create_superuser(username="admin", password="admin", email=None)
so you don’t have to manually set .is_superuser
and .is_staff
to True
.
- [Django]-Django group query by day with timezone specification
- [Django]-Verbose_name_plural unexpected in a model?
Source:stackexchange.com