Skip to content

IsAuthenticated Permission is not working #6

Description

@anjadriano16

When creating a post and there's no user logged in, the result shows "Authentication credentials were not provided", something like that.
When I'm trying to create a post and there's no user logged in, it doesn't show the message above. It still proceed in creating.

What do I need to do?

This the code the I used.

from rest_framework.generics import (
CreateAPIView,
DestroyAPIView,
ListAPIView,
UpdateAPIView,
RetrieveAPIView,
RetrieveUpdateAPIView
)

from rest_framework.permissions import (
AllowAny,
IsAuthenticated,
IsAdminUser,
IsAuthenticatedOrReadOnly,

)

from posts.models import Post

from .permissions import IsOwnerOrReadOnly

from .serializers import (
PostCreateUpdateSerializer,
PostDetailSerializer,
PostListSerializer
)

class PostCreateAPIView(CreateAPIView):
queryset = Post.objects.all()
serializer_class = PostCreateUpdateSerializer
permission_classes = [IsAuthenticated]

def perform_create(self, serializer):
    serializer.save(user=self.request.user)

class PostDetailAPIView(RetrieveAPIView):
queryset = Post.objects.all()
serializer_class = PostDetailSerializer
lookup_field = 'slug'
#lookup_url_kwarg = "abc"

class PostUpdateAPIView(RetrieveUpdateAPIView):
queryset = Post.objects.all()
serializer_class = PostCreateUpdateSerializer
lookup_field = 'slug'
permission_classes = [IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
#lookup_url_kwarg = "abc"
def perform_update(self, serializer):
serializer.save(user=self.request.user)
#email send_email

class PostDeleteAPIView(DestroyAPIView):
queryset = Post.objects.all()
serializer_class = PostDetailSerializer
lookup_field = 'slug'
#lookup_url_kwarg = "abc"

class PostListAPIView(ListAPIView):
queryset = Post.objects.all()
serializer_class = PostListSerializer

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions