Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #28398 -- Add 'Did you mean' suggestions to #9703

merged 1 commit into from Feb 21, 2018
Show file tree
Hide file tree
Changes from all commits
File filter

Filter by extension

Filter by extension

Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions django/core/management/
Expand Up @@ -3,6 +3,7 @@
import pkgutil
import sys
from collections import OrderedDict, defaultdict
from difflib import get_close_matches
from importlib import import_module

import django
Expand Down Expand Up @@ -203,10 +204,11 @@ def fetch_command(self, subcommand):
sys.stderr.write("No Django settings specified.\n")
"Unknown command: %r\nType '%s help' for usage.\n"
% (subcommand, self.prog_name)
possible_matches = get_close_matches(subcommand, commands)
sys.stderr.write('Unknown command: %r' % subcommand)
if possible_matches:
sys.stderr.write('. Did you mean %s?' % possible_matches[0])
sys.stderr.write("\nType '%s help' for usage.\n" % self.prog_name)
if isinstance(app_name, BaseCommand):
# If the command is already loaded, use it directly.
Expand Down
20 changes: 20 additions & 0 deletions tests/admin_scripts/
Expand Up @@ -2256,3 +2256,23 @@ def test_runs_django_admin(self):
def test_program_name_in_help(self):
out, err = self.run_test('-m', ['django', 'help'])
self.assertOutput(out, "Type 'python -m django help <subcommand>' for help on a specific subcommand.")

class DjangoAdminSuggestions(AdminScriptTestCase):
def setUp(self):

def tearDown(self):

def test_suggestions(self):
args = ['rnserver', '--settings=test_project.settings']
out, err = self.run_django_admin(args)
self.assertOutput(err, "Unknown command: 'rnserver'. Did you mean runserver?")

def test_no_suggestions(self):
args = ['abcdef', '--settings=test_project.settings']
out, err = self.run_django_admin(args)
self.assertNotInOutput(err, 'Did you mean')