因此,我尝试在使用django rest框架的应用程序中提供用户注册。我面临的问题是,DRF基本上要求对请求进行身份验证
设置如下:
DEFAULT_AUTHENTICATION = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.OAuth2Authentication',
),
}
观点是:
^{pr2}$这是测试:
def test_user_register(self):
user_data = {'username': 'testusername',
'email': "test@test.com",
'groups': [1],
'password': 'testpassword',
}
resp = self.client.post("/auth/register", json.dumps(user_data), content_type="application/json")
print resp.content
self.assertEquals(resp.status_code, 200)
self.assertContains(resp, user_data["username"], 1, 201)
这是一个错误:
{"detail": "Authentication credentials were not provided."}
我做错什么了?装饰器不应该允许未经身份验证的请求吗? 更棒的是:通过restapi注册用户的正确方法是什么?在
谢谢, 阿迪
检查文档here,上面写着:
相关问题 更多 >
编程相关推荐