私はdjango-rest-frameworkをdjango-oauth-toolkitと統合しました。そしてそれは私に与えている {"detail": "Authentication credentials were not provided."}
未認証のAPIと。
これが私のsettings.pyです。
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"oauth2_provider.contrib.rest_framework.OAuth2Authentication",
),
"DEFAULT_PERMISSION_CLASSES": (
"rest_framework.permissions.IsAuthenticated",
)
}
views.py
from rest_framework.views import APIView
from rest_framework.response import Response
class SignUpView(APIView):
"""
Signup for the user.
"""
def get(self, request):
return Response({"result": True, "message": "User registered successfully."})
urls.py
from django.urls import path
from myapp.views import SignUpView
urlpatterns = [
path("signup/", SignUpView.as_view()),
]
回答:
回答№1は0ユーザーを登録するためには、認証は必要ありません。だからあなたはこのようにあなたの見解を書く必要があります。
class SignUpView(APIView):
"""
Signup for the user.
"""
authentication_classes = ()
permission_classes = ()
def get(self, request):
return Response({"result": True, "message": "User registered successfully."})
他のすべてのリクエストでは、認証トークンをヘッダーに渡す必要があります。その場合は、デフォルトクラスが使用されるため、認証クラスと許可クラスについて言及する必要はありません。