Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsAuthenticated Permission is not working #6

Open
anjadriano16 opened this issue Nov 16, 2017 · 1 comment
Open

IsAuthenticated Permission is not working #6

anjadriano16 opened this issue Nov 16, 2017 · 1 comment

Comments

@anjadriano16
Copy link

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

@4vadim4
Copy link

4vadim4 commented Apr 24, 2021

Edit the question, it's impossible for reading ! Where is the code? Where is the text? I mean, the writing's atrocious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants