Excluding Basic Authentication In A Single View -

2019-04-13 01:40发布

I set basic authentication in my setting.py as follows. Now I need a view that doesn't use basic authentication. How can I do it.

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.BasicAuthentication',),
}

2条回答
Luminary・发光体
2楼-- · 2019-04-13 02:30

To exclude a view from authentication, set authentication_classes and permission_classes to [].

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

    def post(self, request):
        # view code
查看更多
手持菜刀,她持情操
3楼-- · 2019-04-13 02:31

You simply need to set the authentication_classes on your view. Have a look at http://www.django-rest-framework.org/api-guide/authentication/#setting-the-authentication-scheme for an example.

Edit: To remove authentication, set the authentication_classes to an empty list. Don't forget to remove permissions as well since they usually rely on authentication.

查看更多
登录 后发表回答