使用User.objects.get_or_create()在Django中给出无效的密码格式? [英] using User.objects.get_or_create() gives invalid password format in django?
本文介绍了使用User.objects.get_or_create()在Django中给出无效的密码格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
python manage.py shell
>>> from django.contrib.auth.models import User
>>> u=User.objects.get_or_create(username="testuser2",password="123")
>>> u
(<User: testuser2>, True)
似乎创建了用户
正确。但是当我以
http://127.0.0.1:8000/admin/auth/user/3/
登录管理员时,
我看到了密码
的消息无效的密码格式或未知的哈希算法。
seems it created the User
properly. but when I logged into admin at
http://127.0.0.1:8000/admin/auth/user/3/
,
I see this message for password
Invalid password format or unknown hashing algorithm.
此屏幕快照也已附加。为什么这样,以及如何从Shell创建 User对象
。我实际上是在编写一个可为我的项目创建多个用户的脚本吗?
Screenshot is attached too. why is it this way and how to create User objects
from shell. I am actually writing a populating script that create mulitple users for my project?
推荐答案
您需要使用 User.set_password
设置原始密码的方法。
You need to use the User.set_password
method to set a raw password.
例如,
from django.contrib.auth.models import User
user, created = User.objects.get_or_create(username="testuser2")
user.set_password('123')
user.save()
这篇关于使用User.objects.get_or_create()在Django中给出无效的密码格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文