diff --git a/django/contrib/admin/views/decorators.py b/django/contrib/admin/views/decorators.py index cedb1f9cfd4..3039daadb11 100644 --- a/django/contrib/admin/views/decorators.py +++ b/django/contrib/admin/views/decorators.py @@ -85,7 +85,13 @@ def staff_member_required(view_func): if '@' in username: # Mistakenly entered e-mail address instead of username? Look it up. try: - user = User.objects.get(email=username) + users = list(User.objects.filter(email=username)) + if len(users) == 1: + user = users[0] + else: + # Either we cannot find the user, or if more than 1 + # we cannot guess which user is the correct one. + raise User.DoesNotExist() except User.DoesNotExist: message = _("Usernames cannot contain the '@' character.") else: