ok, and? What is the problem ? Postman is saying exactly what is the
problem. If you want to enable sign up without credentials you should
override the permission classes for that endpoint with an empty list or
with AllowAny

>
> class SignUpAPIView(CreateAPIView):
>     serializer_class = SignUpSerializer
>     permission_classes = [AllowAny, ]


Next time please explain your question. And format the text to be easier to
read.
Also read the documentation and use google
https://www.django-rest-framework.org/api-guide/permissions/#allowany


On Thu, Aug 24, 2023 at 3:08 AM Afolabi Oluwapelumi <pelumif...@gmail.com>
wrote:

> I'm writing an api view for sign up for new users but postman is saying :
> {
>     "detail": "Authentication credentials were not provided."
> }
>
>
> this is my view: class SignUpAPIView(CreateAPIView):
>     serializer_class = SignUpSerializer
>
>     def create(self, request, *args, **kwargs):
>         serializer = self.get_serializer(data=request.data)
>
>         if serializer.is_valid():
>             user = serializer.save()
>             return Response({'message': 'User registered successfully'},
> status=status.HTTP_201_CREATED)
>
>         return Response(serializer.errors,
> status=status.HTTP_400_BAD_REQUEST)
>
>
>           And serializer:
> class SignUpSerializer(serializers.ModelSerializer):
>     email = serializers.EmailField(
>         required=True,
>         validators=[UniqueValidator(queryset=User.objects.all())]
>     )
>     password = serializers.CharField(write_only=True, required=True,
> style={'input_type': 'password'})
>     confirm_password = serializers.CharField(write_only=True,
> required=True, style={'input_type': 'password'})
>
>     class Meta:
>         model = User
>         fields = ['first_name', 'last_name', 'email', 'password',
> 'confirm_password']
>
>     def validate(self, data):
>         if data['password'] != data['confirm_password']:
>             raise serializers.ValidationError("Passwords do not match.")
>         return data
>
>     def create(self, validated_data):
>         validated_data.pop('confirm_password', None)
>         return User.objects.create_user(**validated_data)
>
>
>
>
> my settings.py: REST_FRAMEWORK = {
>
>     "DEFAULT_AUTHENTICATION_CLASSES": [
>         "rest_framework_simplejwt.authentication.JWTAuthentication",
>         'rest_framework.authentication.BasicAuthentication',
>         "rest_framework.authentication.SessionAuthentication",
>     ],
>
>     "DEFAULT_PERMISSION_CLASSES": [
>         "rest_framework.permissions.IsAuthenticated"
>     ],
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/2658d6dc-6f6f-4858-aa9a-e900e90d1f73n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-rest-framework/2658d6dc-6f6f-4858-aa9a-e900e90d1f73n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Francisco Pandol

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAK-MxskigGwcRy2K%3DTmNftLQ8zzTUvMTK0bdUEe8Jf1WPQpSHw%40mail.gmail.com.

Reply via email to