3
我正在構建一個公開REST API的Django應用程序,用戶可以通過它來查詢我的應用程序的模型。我按照說明here。如何管理訪問Django REST API的權限?
下面你可以看到我用各種用戶名/密碼從命令行打開這個API。 但是,它只適用於如果我使用root用戶和密碼。爲什麼?我該如何改變它?我沒有指定這個API只對root用戶可用的任何地方。我想這是公開的
% curl -H 'Accept: application/json; indent=4' -u root:myRootPassword http://127.0.0.1:3001/api/profiles/60/
{
"id": 60,
"slug": "my_user",
"user": "http://127.0.0.1:3001/api/users/16/"
}
% curl -H 'Accept: application/json; indent=4' http://127.0.0.1:3001/api/users/16/
{
"detail": "Authentication credentials were not provided."
}
% curl -H 'Accept: application/json; indent=4' -u myUser:myPassword http://127.0.0.1:3001/api/profiles/60/
{
"detail": "You do not have permission to perform this action."
}
% curl -H 'Accept: application/json; indent=4' -u myUser:myPassword http://127.0.0.1:3001/api/profiles/60/
{
"detail": "Invalid username/password"
}