[Django]-Creating a Django admin account: null value of password

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()
👤Seb D.

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.

Leave a comment