I am new to using Django Rest framework, i am following this tutorial Django-Rest-Framework
Instead of snippets my model consists of a userprofile as given belo
In my case the typo was in views.py
. Instead of ...
permission_classes = (permissions.IsAuthenticated,)
... I had ...
permission_classes = (permissions.IsAuthenticated)
As pointed out by Daniel above, i had this stupid snippet in the settings file, which was causing the problem,
#REST_FRAMEWORK = {
# '''Use hyperlinked styles by default'''
# '''only used if serializer_class attribute is not set on a view'''
# 'DEFAULT_MODEL_SERIALIZER_CLASS':
# 'rest_framkework.serializers.HyperLinkedModelSerializer',
# 'DEFAULT_PERMISSION_CLASSES':
# 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
# }
Commmented this and it worked.
Pass the authentication class inside your class instead of in your settings.py if you need authentication just in some classes, and do like this:
authentication_classes = [TokenAuthentication, ]
instead of like this:
authentication_classes = TokenAuthentication
I had the same error when I used custom permissions, because of a 'typo'
I had:
@permission_classes(EventByFacilityPermissions)
class EventByFacilityViewSet(viewsets.ModelViewSet):
instead of:
@permission_classes((EventByFacilityPermissions,))
class EventByFacilityViewSet(viewsets.ModelViewSet):
Just to let others know, I kept getting this same error and found that I forgot to include a comma in my REST_FRAMEWORK
. I had this:
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated'
),
instead of this:
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
The comma defines this as a one-element tuple