[Fixed]-'str' object is not callable Django Rest Framework

22๐Ÿ‘

โœ…

My problem was in my settings.py file:

Diff:

    REST_FRAMEWORK = {
-       'DEFAULT_AUTHENTICATION_CLASSES': {
+       'DEFAULT_AUTHENTICATION_CLASSES': (
            'rest_framework.authentication.SessionAuthentication',
-        }
+        ),
-        'DEFAULT_PERMISSION_CLASSES': {
+        'DEFAULT_PERMISSION_CLASSES': (
            'rest_framework.permissions.IsAuthenticatedOrReadOnly',
-        },
+        ),
    }
๐Ÿ‘คLeon Wright

10๐Ÿ‘

Just want to give an example from the previous correct answers with Django v2.0.6 and Django REST framework v3.8.2.

For example in settings.py:

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

Change:

'DEFAULT_AUTHENTICATION_CLASSES': {
                'rest_framework.authentication.BasicAuthentication',
                'rest_framework.authentication.SessionAuthentication',
                }

Into:

'DEFAULT_AUTHENTICATION_CLASSES': (
                'rest_framework.authentication.BasicAuthentication',
                'rest_framework.authentication.SessionAuthentication',
                )

By just replacing the โ€œ{ }โ€ with โ€œ( )โ€.

๐Ÿ‘คSteven

2๐Ÿ‘

if you are using simple_jwt also check this , donโ€™t use these brackets {} but () and add comma at the end

    SIMPLE_JWT = {
   'AUTH_HEADER_TYPES': ('JWT',),
   'ACCESS_TOKEN_LIFETIME': timedelta(minutes=100),
#    'ROTATE_REFRESH_TOKENS': False,
#    'BLACKLIST_AFTER_ROTATION': False,
#    'UPDATE_LAST_LOGIN': False,
     'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
}

0๐Ÿ‘

just replace {} by () in settings.py REST_FRAMEWORK

๐Ÿ‘คFadex022

Leave a comment