REST_FRAMEWORK = { 'EXCEPTION_HANDLER': 'djangoProject.utils.exception.custom_exception_handler', # 在不需要权限就能访问的视图 设置permissions_classes=[] 设为空就可以 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated',//全局设置 ), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', 'rest_framework.authentication.SessionAuthentication', 'rest_framework.authentication.BasicAuthentication', ), }
以上为django的settings文件,以下为指定的view
class BannerListAPIView(ListAPIView): # authentication_classes = [OpenedAuthentication] permission_classes = []//局部设置会优先于全局设置 queryset = Banner.objects.filter(is_show=True, is_deleted=False).order_by("-orders", "-id")[ :constants.BANNER_LENGTH_LIMIT] serializer_class = BannerModelSerializer
标签:权限,rest,django,framework,authentication,restframework,接口,classes From: https://www.cnblogs.com/aidaminiu/p/16585850.html