Skip to content

Commit

Permalink
Fixed #24857 -- Added "python -m django" entry point.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhiebert authored and timgraham committed Sep 7, 2015
1 parent 1743efb commit 617eff4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions django/__main__.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 7 additions & 1 deletion docs/ref/django-admin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====
Expand All @@ -42,6 +47,7 @@ Usage

$ django-admin <command> [options]
$ manage.py <command> [options]
$ python -m django <command> [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
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/1.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^

Expand Down
9 changes: 9 additions & 0 deletions tests/admin_scripts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2037,3 +2037,12 @@ def test_pks_parsing(self):
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)

0 comments on commit 617eff4

Please sign in to comment.