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
serializers.py 文件源码
python
阅读 30
收藏 0
点赞 0
评论 0
评论列表
文章目录