私の Django REST API には、認証用の次のクラスがあります。
class AuthView(APIView):
authentication_classes = (BasicAuthentication,)
def post(self, request, *args, **kwargs):
login(request, request.user)
data = {'testkey':'testvalue'}
return HttpResponse(json.dumps(data), content_type="application/json")
資格情報が正しければ、200 ステータス コードが返されます (これで問題ありません)。ただし、資格情報が間違っている場合は、デフォルト (401) ステータス コード以外のステータス コードを返したいと考えています。