Hi Folks,
I didn't understand this code, Cab you guys please explain me about this
code:

*views.py:*
*-------------*







*class UserLoginAPIView(GenericAPIView): authentication_classes = ()
permission_classes = () serializer_class = UserLoginSerializer ()def
post(self, request, *args, **kwargs): serializer =
self.get_serializer(data=request.data) if serializer.is_valid(): user =
serializer.user *



*token, _ = Token.objects.get_or_create(user=user) return
Response(data=TokenSerializer(token).data, status=status.HTTP_200_OK) else:
return Response(data=serializer.errors,status=status.HTTP_400_BAD_REQUEST,)*

*seralizers.py*
*-----------------*




















*class UserLoginSerializer(serializers.Serializer):    username =
serializers.CharField(required=True)    password =
serializers.CharField(required=True)    default_error_messages = {
'inactive_account': _('User account is disabled.'),
'invalid_credentials': _('Unable to login with provided credentials.')
}    def __init__(self, *args, **kwargs):        super(UserLoginSerializer,
self).__init__(*args, **kwargs)        self.user = None    def
validate(self, attrs):        self.user =
authenticate(username=attrs.get("username"),
password=attrs.get('password'))        if self.user:            if not
self.user.is_active:                raise
serializers.ValidationError(self.error_messages['inactive_account'])
    return attrs        else:            raise
serializers.ValidationError(self.error_messages['invalid_credentials']*

Here ,
1)  super(UserLoginSerializer, self).__init__(*args, **kwargs)
 what  value  parent will get by using line *super(UserLoginSerializer,
self).__init__(*args, **kwargs) *
2) Validate is one method which take attrs as a argument but If I didn;t
pass value of attrs then how it will be work?

Guys please help me to understand this code.

Thank You

Regards,
Soumen

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

Reply via email to