[Django]-TypeError while using django rest framework tutorial

9๐Ÿ‘

โœ…

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.

๐Ÿ‘คSirius

109๐Ÿ‘

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

๐Ÿ‘คdbryant4

18๐Ÿ‘

In my case the typo was in views.py. Instead of โ€ฆ

permission_classes = (permissions.IsAuthenticated,)

โ€ฆ I had โ€ฆ

permission_classes = (permissions.IsAuthenticated)
๐Ÿ‘คChris

6๐Ÿ‘

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):
๐Ÿ‘คMarco Silva

5๐Ÿ‘

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
๐Ÿ‘คGregory

Leave a comment