无法使用Django的测试客户端登录

2024-09-30 14:21:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的测试.py在

class TestAdding(TestCase):

    def setUp(self):
        username = 'testuser'
        password = 'testpass'
        user = User.objects.create_user(username, password=password)
        self.client = Client()
        logged_in = self.client.login(username=username, password=password)
        self.assertTrue(logged_in)

我得到以下错误

^{pr2}$

我检查了用户是否被创建了,它确实创建了。在

唯一的问题是登录。在

编辑:我的设置文件的这些部分可能是相关的。在

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
    'guardian.backends.ObjectPermissionBackend',
)

ACCOUNT_AUTHENTICATION_METHOD = 'username'

Tags: inpyselfclientauthauthenticationdefusername