在单个视图中排除基本身份验证 - Django Rest Framework

nid*_*hin 2 django-rest-framework

我在我的setting.py中设置了基本身份验证,如下所示.现在我需要一个不使用基本身份验证的视图.我该怎么做.

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.BasicAuthentication',),
}
Run Code Online (Sandbox Code Playgroud)

Chi*_*and 6

要从身份验证中排除视图,请将authentication_classes和设置permission_classes[]

class SignupView(APIView):
    authentication_classes = []
    permission_classes = []

    def post(self, request):
        # view code
Run Code Online (Sandbox Code Playgroud)


Lin*_*via 5

您只需authentication_classes在视图上设置即可.有关示例,查看http://www.django-rest-framework.org/api-guide/authentication/#setting-the-authentication-scheme.

编辑:要删除身份验证,请将其设置authentication_classes为空列表.不要忘记删除权限,因为它们通常依赖于身份验证.