From 617eff41acc583a3b0f97bb6bcc7efe096dc4891 Mon Sep 17 00:00:00 2001 From: Ryan Hiebert Date: Thu, 30 Apr 2015 10:54:45 -0500 Subject: [PATCH] Fixed #24857 -- Added "python -m django" entry point. --- django/__main__.py | 9 +++++++++ docs/ref/django-admin.txt | 8 +++++++- docs/releases/1.9.txt | 3 +++ tests/admin_scripts/tests.py | 9 +++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 django/__main__.py diff --git a/django/__main__.py b/django/__main__.py new file mode 100644 index 0000000000..8b96e91ea8 --- /dev/null +++ b/django/__main__.py @@ -0,0 +1,9 @@ +""" +Invokes django-admin when the django module is run as a script. + +Example: python -m django check +""" +from django.core import management + +if __name__ == "__main__": + management.execute_from_command_line() diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index 4db73e4244..94b12fe9d7 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -33,7 +33,12 @@ Django settings files, use ``django-admin`` with option. The command-line examples throughout this document use ``django-admin`` to -be consistent, but any example can use ``manage.py`` just as well. +be consistent, but any example can use ``manage.py`` or ``python -m django`` +just as well. + +.. versionadded:: 1.9 + + ``python -m django`` was added. Usage ===== @@ -42,6 +47,7 @@ Usage $ django-admin [options] $ manage.py [options] + $ python -m django [options] ``command`` should be one of the commands listed in this document. ``options``, which is optional, should be zero or more of the options available diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index c0b8ed208e..f93b403552 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -415,6 +415,9 @@ Management Commands to the database using the password from your settings file (instead of requiring it to be manually entered). +* The ``django`` package may be run as a script, i.e. ``python -m django``, + which will behave the same as ``django-admin``. + Migrations ^^^^^^^^^^ diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 174cfe687f..616082346b 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -2037,3 +2037,12 @@ class Dumpdata(AdminScriptTestCase): out, err = self.run_manage(args) self.assertOutput(err, "You can only use --pks option with one model") self.assertNoOutput(out) + + +class MainModule(AdminScriptTestCase): + """python -m django works like django-admin.""" + + def test_runs_django_admin(self): + cmd_out, _ = self.run_django_admin(['--version']) + mod_out, _ = self.run_test('-m', ['django', '--version']) + self.assertEqual(mod_out, cmd_out)