Django, can't log in after creating user

后端 未结 1 1390
迷失自我
迷失自我 2021-01-12 21:38

I created user in the Django shell and tried to authenticate it, but can\'t. That returns NoneType. Also, I check that is_superuser, is_stuff, is_active is True

相关标签:
1条回答
  • 2021-01-12 22:07

    You should have used the create_user method, so that the password was hashed correctly:

    User.objects.create_user(username='user', password='password', email='someemail')
    

    If you want the user to be able to access the Django admin, set is_staff=True as well:

    User.objects.create_user(username='user', password='password', email='someemail', is_staff=True)
    

    You can fix the password for the existing user in the Django shell with set_password:

    user = User.objects.get(username='user')
    user.set_password('password')
    user.is_staff = True  # allow user to log in to Django admin
    user.save()
    
    0 讨论(0)
提交回复
热议问题