0
我在views.py以下,Django的休息IsAdminUser不適用
from webapi.models import members
from rest_framework import permissions
from webapi.serializers import MemberSerializer
from rest_framework import generics
class MemberList(generics.ListAPIView):
queryset = members.objects.all()
serializer_class = MemberSerializer
permission_class = (permissions.IsAuthenticated,)
class MemberCreate(generics.CreateAPIView):
queryset = members.objects.all()
serializer_class = MemberSerializer
permission_class = (permissions.IsAdminUser,)
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
在上面IsAuthenticated工作正常,但是當我用「permissions.IsAdminUser」爲MemberCreate類是允許而不是管理用戶也可以創建項目。
按照問題「Django rest_framework IsAdminUser not behaving」我甚至嘗試添加在settings.py以下,但仍重寫沒有發生,
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
)
}
無論添加或不設置增加REST_FRAMEWORK。 py IsAdminUser權限不起作用。