Settings.py
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
Tests.py,其中包含触发错误的代码
class LoginTest(TestCase):
def test_can_redirect_to_user_page_if_authentificated(self):
test_user = User(username='foo', password='bar', first_name='Testy', last_name='McTestingTon', email='[email protected]', is_active=True)
test_user.save()
current_user = authenticate(username=test_user.username, password=test_user.password)
print(current_user)
response = self.client.post('/login', data = {'username' : current_user.username, 'password' : current.password})
self.assertEqual(response.url, '/users/Testy')
[current_user
始终返回为None
我在SO上尝试了其他文章的许多建议,但对于我已将其is_active
明确设置为True
且将ModelBackend
添加到我的settings.py
的用户,authentication仍然返回None。