且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Django,创建用户后无法登录

更新时间:2023-12-03 22:40:28

您应该已经使用了

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')

如果您希望用户能够访问Django管理员,请同时设置is_staff=True:

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()