1

In my settings.py file I have set this:

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ),
}

Now, I have created a ListCreateAPIView:

class ListSubreddits(ListCreateAPIView):
    queryset = Subreddit.objects.all()
    authentication_classes = (JSONWebTokenAuthentication, )

    def get_serializer_class(self):
        if self.request.method == 'GET':
            return SubredditSerializer_detailed
        if self.request.method == 'POST':
            return SubredditSerializer

So, I have sent a POST request creating without just content-type header and the POST request was successful. I haven't provided any Authentication or Authorization headers. What am I missing here?

1
  • please post all info about REST_FRAMEWORK in settings.py Commented Jul 25, 2018 at 1:43

2 Answers 2

3

you must add permission to your view :

from rest_framework import permissions

class ListSubreddits(ListCreateAPIView):

    queryset = Subreddit.objects.all()
    authentication_classes = (JSONWebTokenAuthentication, )
    permission_classes = (permissions.IsAuthenticated, )

    def get_serializer_class(self):
        if self.request.method == 'GET':
            return SubredditSerializer_detailed
        if self.request.method == 'POST':
            return SubredditSerializer
Sign up to request clarification or add additional context in comments.

Comments

0

Change your settings for REST_FRAMEWORK in settings.py to the following:

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    )
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.