全局设置权限
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
)
}
如果没设置,默认允许访问
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.AllowAny',
)
视图中指定权限
from rest_framework import viewsets
from .models import Category
from .serializers import CategorySerializer
from rest_framework.permissions import IsAuthenticated
class CategoryViewSet(viewsets.ModelViewSet):
qu...