According to the Django Rest Framework, when you want to specify what authentication to use, you can either set it as a global in your settings file e.g
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
)
}
or as a per class view e.g
@authentication_classes((SessionAuthentication, TokenAuthentication))
Now what i don't seem to get is that when we specify it as a global in our settings, must we also include it as a per class view.
Here is the code for my class view
from django.http import HttpResponse
from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.authentication import TokenAuthentication, SessionAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
# Create your views here.
@api_view(['GET'])
@authentication_classes((SessionAuthentication, TokenAuthentication))
@permission_classes((IsAuthenticated,))
def index_view(request, format=None):
return Response([str(request.auth), str(request.user.password), str(request.session.username)])
And here is the code in my settings.py file
Rest Framework
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated'
)
}
Please i hope i am specific enough