1 ===========================
2 The django-admin.py utility
3 ===========================
5 ``django-admin.py`` is Django's command-line utility for administrative tasks.
6 This document outlines all it can do.
8 The ``django-admin.py`` script should be on your system path if you installed
9 Django via its setup.py utility. If it's not on your path, you can find it in
10 ``site-packages/django/bin`` within your Python installation. Consider
11 symlinking to it from some place on your path, such as ``/usr/local/bin``.
16 ``django-admin.py action [options]``
18 ``action`` should be one of the actions listed in this document. ``options``,
19 which is optional, should be zero or more of the options listed in this
22 Run ``django-admin.py --help`` to display a help message that includes a terse
23 list of all available actions and options.
25 Most actions take a list of "modelmodule"s. A "modelmodule," in this case, is
26 the name of a file containing Django models. For example, if you have a model
27 module called ``myproject/apps/polls/pollmodels.py``, the "modelmodule" in this
28 case would be ``"pollmodels"``.
33 adminindex [modelmodule modelmodule ...]
34 ----------------------------------------
36 Prints the admin-index template snippet for the given model module(s).
38 Use admin-index template snippets if you want to customize the look and feel of
39 your admin's index page. See `Tutorial 2`_ for more information.
41 .. _Tutorial 2: http://www.djangoproject.com/documentation/tutorial2/
43 createcachetable [tablename]
44 ----------------------------
46 Creates a cache table named ``tablename`` for use with the database cache
47 backend. See the `cache documentation`_ for more information.
49 .. _cache documentation: http://www.djangoproject.com/documentation/cache/
54 Creates a superuser account interactively. It asks you for a username, e-mail
57 **New in Django development version:** You can specify
58 ``username email password`` on the command line, for convenient use in shell
61 django-admin.py createsuperuser john john@example.com mypassword
66 Initializes the database with the tables and data Django needs by default.
67 Specifically, these are the database tables from the ``auth`` and ``core``
73 Introspects the database tables in the given database and outputs a Django
74 model module to standard output.
76 Use this if you have a legacy database with which you'd like to use Django.
77 The script will inspect the database and create a model for each table within
80 This feature is meant as a shortcut, not as definitive model generation. After
81 you run it, you'll want to look over the generated models yourself to make
82 customizations. In particular, you'll need to do this:
84 * Rearrange models' order, so that models that refer to other models are
86 * Add ``primary_key=True`` to one field in each model. The ``inspectdb``
87 doesn't yet introspect primary keys.
89 ``inspectdb`` works with PostgreSQL, MySQL and SQLite. Foreign-key detection
90 only works in PostgreSQL.
92 install [modelmodule modelmodule ...]
93 -------------------------------------
95 Executes the equivalent of ``sqlall`` for the given model module(s).
97 installperms [modelmodule modelmodule ...]
98 ------------------------------------------
100 Installs any admin permissions for the given model module(s) that aren't
101 already installed in the database. Outputs a message telling how many
102 permissions were added, if any.
104 runserver [optional port number, or ipaddr:port]
105 ------------------------------------------------
107 Starts a lightweight development Web server on the local machine. By default,
108 the server runs on port 8000 on the IP address 127.0.0.1. You can pass in an
109 IP address and port number explicitly.
111 If you run this script as a user with normal privileges (recommended), you
112 might not have access to start a port on a low port number. Low port numbers
113 are reserved for superusers (root).
115 DO NOT USE THIS SERVER IN A PRODUCTION SETTING.
117 The development server automatically reloads Python code for each request, as
118 needed. You don't need to restart the server for code changes to take effect.
120 When you start the server, and each time you change Python code while the
121 server is running, the server will validate all of your installed models. (See
122 the "validate" option below.) If the validator finds errors, it will print
123 them to standard output, but it won't stop the server.
125 You can run as many servers as you want, as long as they're on separate ports.
126 Just execute ``django-admin.py runserver`` more than once.
128 Note that the default IP address, 127.0.0.1, is not accessible from other
129 machines on your network. To make your development server viewable to other
130 machines on the network, use its own IP address (e.g. ``192.168.2.1``) or
136 Port 7000 on IP address 127.0.0.1::
138 django-admin.py runserver 7000
140 Port 7000 on IP address 1.2.3.4::
142 django-admin.py runserver 1.2.3.4:7000
144 sql [modelmodule modelmodule ...]
145 ---------------------------------
147 Prints the CREATE TABLE SQL statements for the given model module(s).
149 sqlall [modelmodule modelmodule ...]
150 ------------------------------------
152 Prints the CREATE TABLE and initial-data SQL statements for the given model module(s).
154 sqlclear [modelmodule modelmodule ...]
155 --------------------------------------
157 Prints the DROP TABLE SQL statements for the given model module(s).
159 sqlindexes [modelmodule modelmodule ...]
160 ----------------------------------------
162 Prints the CREATE INDEX SQL statements for the given model module(s).
164 sqlinitialdata [modelmodule modelmodule ...]
165 --------------------------------------------
167 Prints the initial INSERT SQL statements for the given model module(s).
169 sqlreset [modelmodule modelmodule ...]
170 --------------------------------------
172 Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given model module(s).
174 sqlsequencereset [modelmodule modelmodule ...]
175 ----------------------------------------------
177 Prints the SQL statements for resetting PostgreSQL sequences for the given
180 See http://simon.incutio.com/archive/2004/04/21/postgres for more information.
185 Creates a Django app directory structure for the given app name in the current
188 startproject [projectname]
189 --------------------------
191 Creates a Django project directory structure for the given project name in the
197 Validates all installed models (according to the ``INSTALLED_APPS`` setting)
198 and prints validation errors to standard output.
208 django-admin.py init --settings=myproject.settings
210 Explicitly specifies the settings module to use. The settings module should be
211 in Python path syntax, e.g. "myproject.settings". If this isn't provided,
212 ``django-admin.py`` will use the DJANGO_SETTINGS_MODULE environment variable.
219 django-admin.py init --pythonpath='/home/djangoprojects/myproject'
221 Adds the given filesystem path to the Python `import search path`_. If this
222 isn't provided, ``django-admin.py`` will use the ``PYTHONPATH`` environment
225 .. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html
230 Displays a help message that includes a terse list of all available actions and