10 Django RESTful api 實現匿名訪問

 

# views_send_code.py

from rest_framework.permissions import AllowAny

class MsgCodeViewSet(CreateModelMixin, viewsets.GenericViewSet):

    serializer_class = MsgCodeSerializer
    pagination_class = StandardResultsSetPagination
    
    # 認證策略屬性
    authentication_classes = ()
    # 權限策略屬性
    permission_classes = (AllowAny, )

 解決問題:不用登陸,就能夠訪問apiapi

 

其餘:spa

#permission是用來作權限判斷的
# IsAuthenticated:必須登陸用戶;IsOwnerOrReadOnly:必須是當前登陸的用戶
permission_classes = (IsAuthenticated,IsOwnerOrReadOnly)
相關文章
相關標籤/搜索