diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 43598e2fb9..b68692d60a 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -149,6 +149,8 @@ class ManagementUtility: def __init__(self, argv=None): self.argv = argv or sys.argv[:] self.prog_name = os.path.basename(self.argv[0]) + if self.prog_name == '__main__.py': + self.prog_name = 'python -m django' self.settings_exception = None def main_help_text(self, commands_only=False): diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index d90456ac13..b8bcea35f0 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -2223,3 +2223,7 @@ class MainModule(AdminScriptTestCase): cmd_out, _ = self.run_django_admin(['--version']) mod_out, _ = self.run_test('-m', ['django', '--version']) self.assertEqual(mod_out, cmd_out) + + def test_program_name_in_help(self): + out, err = self.run_test('-m', ['django', 'help']) + self.assertOutput(out, "Type 'python -m django help ' for help on a specific subcommand.")