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, )

 解决问题:不用登录,就可以访问api

 

其他:

#permission是用来做权限判断的
# IsAuthenticated:必须登录用户;IsOwnerOrReadOnly:必须是当前登录的用户
permission_classes = (IsAuthenticated,IsOwnerOrReadOnly)

 

posted @ 2019-04-10 15:26  huangyanpeng  阅读(643)  评论(0编辑  收藏  举报