【发布时间】:2016-10-10 16:48:40
【问题描述】:
我正在尝试从 rest_framework.authtoken.models 导入令牌生成令牌。视图已成功创建,但我正在使用来自 rest_framework.test 导入 APIClient 的 APIClient() 为 post api 编写测试。 def test_address_api_auth_token(self):
data = {
"username": self.user.username,
"password": self.user.password
}
self.client.force_authenticate(user=self.user)
response = self.client.post('/api-token-auth/', data, format='json')
self.assertEqual(response.status_code, 200)
虽然用户和密码是由模型创建的。但我仍然收到此错误-> AssertionError: 400 != 200。 错误信息 -> 用户名和密码无效。
【问题讨论】:
标签: python-2.7 django-rest-framework http-post auth-token apiclient