Nidhin
Nidhin

Reputation: 636

Excluding Basic Authentication In A Single View - Django Rest Framework

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

Upvotes: 7

Views: 5989

Answers (2)

Chillar Anand
Chillar Anand

Reputation: 29594

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

Upvotes: 10

Linovia
Linovia

Reputation: 20996

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.

Upvotes: 7

Related Questions