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.
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]
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"
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