0
我正在嘗試爲我的api設置身份驗證。我是API新手,但希望製作更多基於客戶端的網絡應用程序。我試圖解決的第一個問題是客戶端身份驗證。我去http://127.0.0.1:8000/o/applications/
(我想我需要去這就是),但它重定向我http://127.0.0.1:8000/accounts/login/?next=/o/applications/
找不到網頁django rest framewok與django oauth工具包
繼承人我的代碼:
Settings.py:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
),
'DEFAULT_PARSER_CLASSES': (
'rest_framework.parsers.JSONParser',
urls.py:
url(r'^api/users/$', api.UserList.as_view()),
url(r'^api/users/(?P<pk>[0-9+]+)/$', api.UserDetail.as_view()),
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
api.py
from django.contrib.auth.models import User
from django.http import HttpResponse
from rest_framework import generics
from oauth2_provider.views.generic import ProtectedResourceView
from serializers import UserSerializer
class APIEndpoint(ProtectedResourceView):
def get(self, request, *args, **kwargs):
return HttpResponse('Protected with OAuth2!')
class UserList(generics.ListCreateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
class UserDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer