| 1 |
=========================== |
|---|
| 2 |
The django-admin.py utility |
|---|
| 3 |
=========================== |
|---|
| 4 |
|
|---|
| 5 |
``django-admin.py`` is Django's command-line utility for administrative tasks. |
|---|
| 6 |
This document outlines all it can do. |
|---|
| 7 |
|
|---|
| 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``. |
|---|
| 12 |
|
|---|
| 13 |
Usage |
|---|
| 14 |
===== |
|---|
| 15 |
|
|---|
| 16 |
``django-admin.py action [options]`` |
|---|
| 17 |
|
|---|
| 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 |
|---|
| 20 |
document. |
|---|
| 21 |
|
|---|
| 22 |
Run ``django-admin.py --help`` to display a help message that includes a terse |
|---|
| 23 |
list of all available actions and options. |
|---|
| 24 |
|
|---|
| 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"``. |
|---|
| 29 |
|
|---|
| 30 |
Available actions |
|---|
| 31 |
================= |
|---|
| 32 |
|
|---|
| 33 |
adminindex [modelmodule modelmodule ...] |
|---|
| 34 |
---------------------------------------- |
|---|
| 35 |
|
|---|
| 36 |
Prints the admin-index template snippet for the given model module(s). |
|---|
| 37 |
|
|---|
| 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. |
|---|
| 40 |
|
|---|
| 41 |
.. _Tutorial 2: http://www.djangoproject.com/documentation/tutorial2/ |
|---|
| 42 |
|
|---|
| 43 |
createcachetable [tablename] |
|---|
| 44 |
---------------------------- |
|---|
| 45 |
|
|---|
| 46 |
Creates a cache table named ``tablename`` for use with the database cache |
|---|
| 47 |
backend. See the `cache documentation`_ for more information. |
|---|
| 48 |
|
|---|
| 49 |
.. _cache documentation: http://www.djangoproject.com/documentation/cache/ |
|---|
| 50 |
|
|---|
| 51 |
createsuperuser |
|---|
| 52 |
--------------- |
|---|
| 53 |
|
|---|
| 54 |
Creates a superuser account interactively. It asks you for a username, e-mail |
|---|
| 55 |
address and password. |
|---|
| 56 |
|
|---|
| 57 |
init |
|---|
| 58 |
---- |
|---|
| 59 |
|
|---|
| 60 |
Initializes the database with the tables and data Django needs by default. |
|---|
| 61 |
Specifically, these are the database tables from the ``auth`` and ``core`` |
|---|
| 62 |
models. |
|---|
| 63 |
|
|---|
| 64 |
inspectdb [dbname] |
|---|
| 65 |
------------------ |
|---|
| 66 |
|
|---|
| 67 |
Introspects the database tables in the given database and outputs a Django |
|---|
| 68 |
model module to standard output. |
|---|
| 69 |
|
|---|
| 70 |
Use this if you have a legacy database with which you'd like to use Django. |
|---|
| 71 |
The script will inspect the database and create a model for each table within |
|---|
| 72 |
it. |
|---|
| 73 |
|
|---|
| 74 |
This feature is meant as a shortcut, not as definitive model generation. After |
|---|
| 75 |
you run it, you'll want to look over the generated models yourself to make |
|---|
| 76 |
customizations. In particular, you'll need to do this: |
|---|
| 77 |
|
|---|
| 78 |
* Rearrange models' order, so that models that refer to other models are |
|---|
| 79 |
ordered properly. |
|---|
| 80 |
* Add ``primary_key=True`` to one field in each model. The ``inspectdb`` |
|---|
| 81 |
doesn't yet introspect primary keys. |
|---|
| 82 |
|
|---|
| 83 |
``inspectdb`` only works with PostgreSQL and MySQL. Foreign-key detection only |
|---|
| 84 |
works in PostgreSQL. |
|---|
| 85 |
|
|---|
| 86 |
install [modelmodule modelmodule ...] |
|---|
| 87 |
------------------------------------- |
|---|
| 88 |
|
|---|
| 89 |
Executes the equivalent of ``sqlall`` for the given model module(s). |
|---|
| 90 |
|
|---|
| 91 |
installperms [modelmodule modelmodule ...] |
|---|
| 92 |
------------------------------------------ |
|---|
| 93 |
|
|---|
| 94 |
Installs any admin permissions for the given model module(s) that aren't |
|---|
| 95 |
already installed in the database. Outputs a message telling how many |
|---|
| 96 |
permissions were added, if any. |
|---|
| 97 |
|
|---|
| 98 |
runserver [optional port number, or ipaddr:port] |
|---|
| 99 |
------------------------------------------------ |
|---|
| 100 |
|
|---|
| 101 |
Starts a lightweight development Web server on the local machine. By default, |
|---|
| 102 |
the server runs on port 8000 on the IP address 127.0.0.1. You can pass in an |
|---|
| 103 |
IP address and port number explicitly. |
|---|
| 104 |
|
|---|
| 105 |
If you run this script as a user with normal privileges (recommended), you |
|---|
| 106 |
might not have access to start a port on a low port number. Low port numbers |
|---|
| 107 |
are reserved for superusers (root). |
|---|
| 108 |
|
|---|
| 109 |
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. |
|---|
| 110 |
|
|---|
| 111 |
The development server automatically reloads Python code for each request, as |
|---|
| 112 |
needed. You don't need to restart the server for code changes to take effect. |
|---|
| 113 |
|
|---|
| 114 |
When you start the server, and each time you change Python code while the |
|---|
| 115 |
server is running, the server will validate all of your installed models. (See |
|---|
| 116 |
the "validate" option below.) If the validator finds errors, it will print |
|---|
| 117 |
them to standard output, but it won't stop the server. |
|---|
| 118 |
|
|---|
| 119 |
You can run as many servers as you want, as long as they're on separate ports. |
|---|
| 120 |
Just execute ``django-admin.py runserver`` more than once. |
|---|
| 121 |
|
|---|
| 122 |
Note that the default IP address, 127.0.0.1, is not accessible from other |
|---|
| 123 |
machines on your network. To make your development server viewable to other |
|---|
| 124 |
machines on the network, use its own IP address (e.g. ``192.168.2.1``) or |
|---|
| 125 |
``0.0.0.0``. |
|---|
| 126 |
|
|---|
| 127 |
Examples: |
|---|
| 128 |
~~~~~~~~~ |
|---|
| 129 |
|
|---|
| 130 |
Port 7000 on IP address 127.0.0.1:: |
|---|
| 131 |
|
|---|
| 132 |
django-admin.py runserver 7000 |
|---|
| 133 |
|
|---|
| 134 |
Port 7000 on IP address 1.2.3.4:: |
|---|
| 135 |
|
|---|
| 136 |
django-admin.py runserver 1.2.3.4:7000 |
|---|
| 137 |
|
|---|
| 138 |
sql [modelmodule modelmodule ...] |
|---|
| 139 |
--------------------------------- |
|---|
| 140 |
|
|---|
| 141 |
Prints the CREATE TABLE SQL statements for the given model module(s). |
|---|
| 142 |
|
|---|
| 143 |
sqlall [modelmodule modelmodule ...] |
|---|
| 144 |
------------------------------------ |
|---|
| 145 |
|
|---|
| 146 |
Prints the CREATE TABLE and initial-data SQL statements for the given model module(s). |
|---|
| 147 |
|
|---|
| 148 |
sqlclear [modelmodule modelmodule ...] |
|---|
| 149 |
-------------------------------------- |
|---|
| 150 |
|
|---|
| 151 |
Prints the DROP TABLE SQL statements for the given model module(s). |
|---|
| 152 |
|
|---|
| 153 |
sqlindexes [modelmodule modelmodule ...] |
|---|
| 154 |
---------------------------------------- |
|---|
| 155 |
|
|---|
| 156 |
Prints the CREATE INDEX SQL statements for the given model module(s). |
|---|
| 157 |
|
|---|
| 158 |
sqlinitialdata [modelmodule modelmodule ...] |
|---|
| 159 |
-------------------------------------------- |
|---|
| 160 |
|
|---|
| 161 |
Prints the initial INSERT SQL statements for the given model module(s). |
|---|
| 162 |
|
|---|
| 163 |
sqlreset [modelmodule modelmodule ...] |
|---|
| 164 |
-------------------------------------- |
|---|
| 165 |
|
|---|
| 166 |
Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given model module(s). |
|---|
| 167 |
|
|---|
| 168 |
sqlsequencereset [modelmodule modelmodule ...] |
|---|
| 169 |
---------------------------------------------- |
|---|
| 170 |
|
|---|
| 171 |
Prints the SQL statements for resetting PostgreSQL sequences for the given |
|---|
| 172 |
model module(s). |
|---|
| 173 |
|
|---|
| 174 |
See http://simon.incutio.com/archive/2004/04/21/postgres for more information. |
|---|
| 175 |
|
|---|
| 176 |
startapp [appname] |
|---|
| 177 |
------------------ |
|---|
| 178 |
|
|---|
| 179 |
Creates a Django app directory structure for the given app name in the current |
|---|
| 180 |
directory. |
|---|
| 181 |
|
|---|
| 182 |
startproject [projectname] |
|---|
| 183 |
-------------------------- |
|---|
| 184 |
|
|---|
| 185 |
Creates a Django project directory structure for the given project name in the |
|---|
| 186 |
current directory. |
|---|
| 187 |
|
|---|
| 188 |
validate |
|---|
| 189 |
-------- |
|---|
| 190 |
|
|---|
| 191 |
Validates all installed models (according to the ``INSTALLED_APPS`` setting) |
|---|
| 192 |
and prints validation errors to standard output. |
|---|
| 193 |
|
|---|
| 194 |
Available options |
|---|
| 195 |
================= |
|---|
| 196 |
|
|---|
| 197 |
--settings |
|---|
| 198 |
---------- |
|---|
| 199 |
|
|---|
| 200 |
Example usage:: |
|---|
| 201 |
|
|---|
| 202 |
django-admin.py init --settings=myproject.settings |
|---|
| 203 |
|
|---|
| 204 |
Explicitly specifies the settings module to use. The settings module should be |
|---|
| 205 |
in Python path syntax, e.g. "myproject.settings". If this isn't provided, |
|---|
| 206 |
``django-admin.py`` will use the DJANGO_SETTINGS_MODULE environment variable. |
|---|
| 207 |
|
|---|
| 208 |
--pythonpath |
|---|
| 209 |
------------ |
|---|
| 210 |
|
|---|
| 211 |
Example usage:: |
|---|
| 212 |
|
|---|
| 213 |
django-admin.py init --pythonpath='/home/djangoprojects/myproject' |
|---|
| 214 |
|
|---|
| 215 |
Adds the given filesystem path to the Python `import search path`_. If this |
|---|
| 216 |
isn't provided, ``django-admin.py`` will use the ``PYTHONPATH`` environment |
|---|
| 217 |
variable. |
|---|
| 218 |
|
|---|
| 219 |
.. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html |
|---|
| 220 |
|
|---|
| 221 |
--help |
|---|
| 222 |
------ |
|---|
| 223 |
|
|---|
| 224 |
Displays a help message that includes a terse list of all available actions and |
|---|
| 225 |
options. |
|---|