def get_user_by_username(username, active_only=False):
"""
Get a User object by username, whose attributes match those in the database.
:param username: Username to query by
:param active_only: Set this flag to True to only query for active users
:return: User object for that username
:raises UserDoesNotExistException: If no user exists with the given username
"""
if active_only:
user = models.User.query.filter_by(username=username.lower(), is_active=True).first()
else:
user = models.User.query.filter_by(username=username.lower()).first()
if not user:
raise UserDoesNotExistException('No user with username {username} exists'.format(username=username))
return user
评论列表
文章目录