serializers.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:django-rest-framework-sso 作者: namespace-ee 项目源码 文件源码
def validate(self, attrs):
        username = attrs.get('username')
        password = attrs.get('password')

        if username and password:
            user = authenticate(username=username, password=password)

            if user:
                if not user.is_active:
                    msg = _('User account is disabled.')
                    raise serializers.ValidationError(msg)
            else:
                msg = _('Unable to log in with provided credentials.')
                raise serializers.ValidationError(msg)
        else:
            msg = _('Must include "username" and "password".')
            raise serializers.ValidationError(msg)

        attrs['user'] = user
        return attrs
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号