Django测试登录失败

2024-06-26 14:46:29 发布

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

我试图用Django做一些简单的测试,但是我不能成功地用这个用户登录。这是我的密码:

def createUser(isadmin):
    u = User.objects.create_user(username="Test" + ("Admin" if isadmin else "Regular"), password="test")
    return u

def loginUser(self, theusername, thepassword):

    print(theusername + " " + thepassword)
    a = self.client.login(username = theusername, password = thepassword)
    # Prints false - should be true, right?
    print(a)

之后的某个地方:

class DailyEntriesIntTests(TestCase):
    def setUp(self):
        self.client = Client()
        u = createUser(False)
        loginUser(self, u.username, u.password)

我登录不就需要这些吗?你知道吗


Tags: django用户selfclientdefusernamepasswordprint