如果我为测试创建示例用户帐户,则会出现此错误:
未知密码散列算法“password1”。您是否在 PASSWORD_HASHERS 设置中指定了它?
class ExampleTest(TestCase):
def test_sample_data(self):
for i in range(0,1):
user = content.factories.UserFactory.create()
工厂.py:
class UserFactory(factory.Factory):
FACTORY_FOR = User
username = factory.Sequence(lambda n: 'User' + n)
email = 'mail@gmail.com'
password = 'password1'
如何解决?
编辑:
解决方案:
user = content.factories.UserFactory.create()
user.set_password('yourpassword')
user.save()