django-admin.txt 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  1. =============================
  2. django-admin.py and manage.py
  3. =============================
  4. ``django-admin.py`` is Django's command-line utility for administrative tasks.
  5. This document outlines all it can do.
  6. In addition, ``manage.py`` is automatically created in each Django project.
  7. ``manage.py`` is a thin wrapper around ``django-admin.py`` that takes care of
  8. two things for you before delegating to ``django-admin.py``:
  9. * It puts your project's package on ``sys.path``.
  10. * It sets the :envvar:`DJANGO_SETTINGS_MODULE` environment variable so that
  11. it points to your project's ``settings.py`` file.
  12. The ``django-admin.py`` script should be on your system path if you installed
  13. Django via its ``setup.py`` utility. If it's not on your path, you can find it
  14. in ``site-packages/django/bin`` within your Python installation. Consider
  15. symlinking it from some place on your path, such as ``/usr/local/bin``.
  16. For Windows users, who do not have symlinking functionality available, you can
  17. copy ``django-admin.py`` to a location on your existing path or edit the
  18. ``PATH`` settings (under ``Settings - Control Panel - System - Advanced -
  19. Environment...``) to point to its installed location.
  20. Generally, when working on a single Django project, it's easier to use
  21. ``manage.py``. Use ``django-admin.py`` with ``DJANGO_SETTINGS_MODULE``, or the
  22. ``--settings`` command line option, if you need to switch between multiple
  23. Django settings files.
  24. The command-line examples throughout this document use ``django-admin.py`` to
  25. be consistent, but any example can use ``manage.py`` just as well.
  26. Usage
  27. =====
  28. .. code-block:: bash
  29. django-admin.py <command> [options]
  30. manage.py <command> [options]
  31. ``command`` should be one of the commands listed in this document.
  32. ``options``, which is optional, should be zero or more of the options available
  33. for the given command.
  34. Getting runtime help
  35. --------------------
  36. .. django-admin-option:: --help
  37. Run ``django-admin.py help`` to display a list of all available commands.
  38. Run ``django-admin.py help <command>`` to display a description of the
  39. given command and a list of its available options.
  40. App names
  41. ---------
  42. Many commands take a list of "app names." An "app name" is the basename of
  43. the package containing your models. For example, if your ``INSTALLED_APPS``
  44. contains the string ``'mysite.blog'``, the app name is ``blog``.
  45. Determining the version
  46. -----------------------
  47. .. django-admin-option:: --version
  48. Run ``django-admin.py --version`` to display the current Django version.
  49. Examples of output::
  50. 0.95
  51. 0.96
  52. 0.97-pre-SVN-6069
  53. Displaying debug output
  54. -----------------------
  55. Use :djadminopt:`--verbosity` to specify the amount of notification and debug information
  56. that ``django-admin.py`` should print to the console. For more details, see the
  57. documentation for the :djadminopt:`--verbosity` option.
  58. Available commands
  59. ==================
  60. cleanup
  61. -------
  62. .. django-admin:: cleanup
  63. Can be run as a cronjob or directly to clean out old data from the database
  64. (only expired sessions at the moment).
  65. compilemessages
  66. ---------------
  67. .. django-admin:: compilemessages
  68. Compiles .po files created with ``makemessages`` to .mo files for use with
  69. the builtin gettext support. See :doc:`/topics/i18n/index`.
  70. Use the :djadminopt:`--locale` option to specify the locale to process.
  71. If not provided, all locales are processed.
  72. Example usage::
  73. django-admin.py compilemessages --locale=br_PT
  74. createcachetable
  75. ----------------
  76. .. django-admin:: createcachetable
  77. Creates a cache table named ``tablename`` for use with the database cache
  78. backend. See :doc:`/topics/cache` for more information.
  79. .. versionadded:: 1.2
  80. The :djadminopt:`--database` option can be used to specify the database
  81. onto which the cachetable will be installed.
  82. dbshell
  83. -------
  84. .. django-admin:: dbshell
  85. Runs the command-line client for the database engine specified in your
  86. ``ENGINE`` setting, with the connection parameters specified in your
  87. ``USER``, ``PASSWORD``, etc., settings.
  88. * For PostgreSQL, this runs the ``psql`` command-line client.
  89. * For MySQL, this runs the ``mysql`` command-line client.
  90. * For SQLite, this runs the ``sqlite3`` command-line client.
  91. This command assumes the programs are on your ``PATH`` so that a simple call to
  92. the program name (``psql``, ``mysql``, ``sqlite3``) will find the program in
  93. the right place. There's no way to specify the location of the program
  94. manually.
  95. .. versionadded:: 1.2
  96. The :djadminopt:`--database` option can be used to specify the database
  97. onto which to open a shell.
  98. diffsettings
  99. ------------
  100. .. django-admin:: diffsettings
  101. Displays differences between the current settings file and Django's default
  102. settings.
  103. Settings that don't appear in the defaults are followed by ``"###"``. For
  104. example, the default settings don't define ``ROOT_URLCONF``, so
  105. ``ROOT_URLCONF`` is followed by ``"###"`` in the output of ``diffsettings``.
  106. Note that Django's default settings live in ``django/conf/global_settings.py``,
  107. if you're ever curious to see the full list of defaults.
  108. dumpdata <appname appname appname.Model ...>
  109. --------------------------------------------
  110. .. django-admin:: dumpdata
  111. Outputs to standard output all data in the database associated with the named
  112. application(s).
  113. If no application name is provided, all installed applications will be dumped.
  114. The output of ``dumpdata`` can be used as input for ``loaddata``.
  115. Note that ``dumpdata`` uses the default manager on the model for selecting the
  116. records to dump. If you're using a :ref:`custom manager <custom-managers>` as
  117. the default manager and it filters some of the available records, not all of the
  118. objects will be dumped.
  119. .. versionadded:: 1.3
  120. The :djadminopt:`--all` option may be provided to specify that
  121. ``dumpdata`` should use Django's base manager, dumping records which
  122. might otherwise be filtered or modified by a custom manager.
  123. .. django-admin-option:: --format <fmt>
  124. By default, ``dumpdata`` will format its output in JSON, but you can use the
  125. ``--format`` option to specify another format. Currently supported formats
  126. are listed in :ref:`serialization-formats`.
  127. .. django-admin-option:: --indent <num>
  128. By default, ``dumpdata`` will output all data on a single line. This isn't
  129. easy for humans to read, so you can use the ``--indent`` option to
  130. pretty-print the output with a number of indentation spaces.
  131. The :djadminopt:`--exclude` option may be provided to prevent specific
  132. applications from being dumped.
  133. .. versionadded:: 1.3
  134. The :djadminopt:`--exclude` option may also be provided to prevent specific
  135. models (specified as in the form of ``appname.ModelName``) from being dumped.
  136. In addition to specifying application names, you can provide a list of
  137. individual models, in the form of ``appname.Model``. If you specify a model
  138. name to ``dumpdata``, the dumped output will be restricted to that model,
  139. rather than the entire application. You can also mix application names and
  140. model names.
  141. .. versionadded:: 1.2
  142. The :djadminopt:`--database` option can be used to specify the database
  143. onto which the data will be loaded.
  144. .. django-admin-option:: --natural
  145. .. versionadded:: 1.2
  146. Use :ref:`natural keys <topics-serialization-natural-keys>` to represent
  147. any foreign key and many-to-many relationship with a model that provides
  148. a natural key definition. If you are dumping ``contrib.auth`` ``Permission``
  149. objects or ``contrib.contenttypes`` ``ContentType`` objects, you should
  150. probably be using this flag.
  151. flush
  152. -----
  153. .. django-admin:: flush
  154. Returns the database to the state it was in immediately after syncdb was
  155. executed. This means that all data will be removed from the database, any
  156. post-synchronization handlers will be re-executed, and the ``initial_data``
  157. fixture will be re-installed.
  158. The :djadminopt:`--noinput` option may be provided to suppress all user
  159. prompts.
  160. .. versionadded:: 1.2
  161. The :djadminopt:`--database` option may be used to specify the database
  162. to flush.
  163. inspectdb
  164. ---------
  165. .. django-admin:: inspectdb
  166. Introspects the database tables in the database pointed-to by the
  167. ``NAME`` setting and outputs a Django model module (a ``models.py``
  168. file) to standard output.
  169. Use this if you have a legacy database with which you'd like to use Django.
  170. The script will inspect the database and create a model for each table within
  171. it.
  172. As you might expect, the created models will have an attribute for every field
  173. in the table. Note that ``inspectdb`` has a few special cases in its field-name
  174. output:
  175. * If ``inspectdb`` cannot map a column's type to a model field type, it'll
  176. use ``TextField`` and will insert the Python comment
  177. ``'This field type is a guess.'`` next to the field in the generated
  178. model.
  179. * If the database column name is a Python reserved word (such as
  180. ``'pass'``, ``'class'`` or ``'for'``), ``inspectdb`` will append
  181. ``'_field'`` to the attribute name. For example, if a table has a column
  182. ``'for'``, the generated model will have a field ``'for_field'``, with
  183. the ``db_column`` attribute set to ``'for'``. ``inspectdb`` will insert
  184. the Python comment
  185. ``'Field renamed because it was a Python reserved word.'`` next to the
  186. field.
  187. This feature is meant as a shortcut, not as definitive model generation. After
  188. you run it, you'll want to look over the generated models yourself to make
  189. customizations. In particular, you'll need to rearrange models' order, so that
  190. models that refer to other models are ordered properly.
  191. Primary keys are automatically introspected for PostgreSQL, MySQL and
  192. SQLite, in which case Django puts in the ``primary_key=True`` where
  193. needed.
  194. ``inspectdb`` works with PostgreSQL, MySQL and SQLite. Foreign-key detection
  195. only works in PostgreSQL and with certain types of MySQL tables.
  196. .. versionadded:: 1.2
  197. The :djadminopt:`--database` option may be used to specify the
  198. database to introspect.
  199. loaddata <fixture fixture ...>
  200. ------------------------------
  201. .. django-admin:: loaddata
  202. Searches for and loads the contents of the named fixture into the database.
  203. .. versionadded:: 1.2
  204. The :djadminopt:`--database` option can be used to specify the database
  205. onto which the data will be loaded.
  206. What's a "fixture"?
  207. ~~~~~~~~~~~~~~~~~~~
  208. A *fixture* is a collection of files that contain the serialized contents of
  209. the database. Each fixture has a unique name, and the files that comprise the
  210. fixture can be distributed over multiple directories, in multiple applications.
  211. Django will search in three locations for fixtures:
  212. 1. In the ``fixtures`` directory of every installed application
  213. 2. In any directory named in the ``FIXTURE_DIRS`` setting
  214. 3. In the literal path named by the fixture
  215. Django will load any and all fixtures it finds in these locations that match
  216. the provided fixture names.
  217. If the named fixture has a file extension, only fixtures of that type
  218. will be loaded. For example::
  219. django-admin.py loaddata mydata.json
  220. would only load JSON fixtures called ``mydata``. The fixture extension
  221. must correspond to the registered name of a
  222. :ref:`serializer <serialization-formats>` (e.g., ``json`` or ``xml``).
  223. If you omit the extensions, Django will search all available fixture types
  224. for a matching fixture. For example::
  225. django-admin.py loaddata mydata
  226. would look for any fixture of any fixture type called ``mydata``. If a fixture
  227. directory contained ``mydata.json``, that fixture would be loaded
  228. as a JSON fixture.
  229. The fixtures that are named can include directory components. These
  230. directories will be included in the search path. For example::
  231. django-admin.py loaddata foo/bar/mydata.json
  232. would search ``<appname>/fixtures/foo/bar/mydata.json`` for each installed
  233. application, ``<dirname>/foo/bar/mydata.json`` for each directory in
  234. ``FIXTURE_DIRS``, and the literal path ``foo/bar/mydata.json``.
  235. When fixture files are processed, the data is saved to the database as is.
  236. Model defined ``save`` methods and ``pre_save`` signals are not called.
  237. Note that the order in which fixture files are processed is undefined. However,
  238. all fixture data is installed as a single transaction, so data in
  239. one fixture can reference data in another fixture. If the database backend
  240. supports row-level constraints, these constraints will be checked at the
  241. end of the transaction.
  242. The ``dumpdata`` command can be used to generate input for ``loaddata``.
  243. Compressed fixtures
  244. ~~~~~~~~~~~~~~~~~~~
  245. Fixtures may be compressed in ``zip``, ``gz``, or ``bz2`` format. For example::
  246. django-admin.py loaddata mydata.json
  247. would look for any of ``mydata.json``, ``mydata.json.zip``,
  248. ``mydata.json.gz``, or ``mydata.json.bz2``. The first file contained within a
  249. zip-compressed archive is used.
  250. Note that if two fixtures with the same name but different
  251. fixture type are discovered (for example, if ``mydata.json`` and
  252. ``mydata.xml.gz`` were found in the same fixture directory), fixture
  253. installation will be aborted, and any data installed in the call to
  254. ``loaddata`` will be removed from the database.
  255. .. admonition:: MySQL and Fixtures
  256. Unfortunately, MySQL isn't capable of completely supporting all the
  257. features of Django fixtures. If you use MyISAM tables, MySQL doesn't
  258. support transactions or constraints, so you won't get a rollback if
  259. multiple transaction files are found, or validation of fixture data.
  260. If you use InnoDB tables, you won't be able to have any forward
  261. references in your data files - MySQL doesn't provide a mechanism to
  262. defer checking of row constraints until a transaction is committed.
  263. Database-specific fixtures
  264. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  265. If you are in a multi-database setup, you may have fixture data that
  266. you want to load onto one database, but not onto another. In this
  267. situation, you can add database identifier into . If your
  268. :setting:`DATABASES` setting has a 'master' database defined, you can
  269. define the fixture ``mydata.master.json`` or
  270. ``mydata.master.json.gz``. This fixture will only be loaded if you
  271. have specified that you want to load data onto the ``master``
  272. database.
  273. makemessages
  274. ------------
  275. .. django-admin:: makemessages
  276. Runs over the entire source tree of the current directory and pulls out all
  277. strings marked for translation. It creates (or updates) a message file in the
  278. conf/locale (in the django tree) or locale (for project and application)
  279. directory. After making changes to the messages files you need to compile them
  280. with ``compilemessages`` for use with the builtin gettext support. See the
  281. :ref:`i18n documentation <how-to-create-language-files>` for details.
  282. .. django-admin-option:: --all
  283. Use the ``--all`` or ``-a`` option to update the message files for all
  284. available languages.
  285. Example usage::
  286. django-admin.py makemessages --all
  287. .. django-admin-option:: --extension
  288. Use the ``--extension`` or ``-e`` option to specify a list of file extensions
  289. to examine (default: ".html").
  290. Example usage::
  291. django-admin.py makemessages --locale=de --extension xhtml
  292. Separate multiple extensions with commas or use -e or --extension multiple times::
  293. django-admin.py makemessages --locale=de --extension=html,txt --extension xml
  294. Use the :djadminopt:`--locale` option to specify the locale to process.
  295. Example usage::
  296. django-admin.py makemessages --locale=br_PT
  297. .. django-admin-option:: --domain
  298. Use the ``--domain`` or ``-d`` option to change the domain of the messages files.
  299. Currently supported:
  300. * ``django`` for all ``*.py`` and ``*.html`` files (default)
  301. * ``djangojs`` for ``*.js`` files
  302. .. django-admin-option:: --symlinks
  303. .. versionadded:: 1.2
  304. Use the ``--symlinks`` or ``-s`` option to follow symlinks to directories when
  305. looking for new translation strings.
  306. Example usage::
  307. django-admin.py makemessages --locale=de --symlinks
  308. .. django-admin-option:: --ignore
  309. Use the ``--ignore`` or ``-i`` option to ignore files or directories matching
  310. the given `glob-style pattern`_. Use multiple times to ignore more.
  311. These patterns are used by default: ``'CVS'``, ``'.*'``, ``'*~'``
  312. Example usage::
  313. django-admin.py makemessages --locale=en_US --ignore=apps/* --ignore=secret/*.html
  314. .. _`glob-style pattern`: http://docs.python.org/library/glob.html
  315. .. django-admin-option:: --no-default-ignore
  316. Use the ``--no-default-ignore`` option to disable the default values of
  317. :djadminopt:`--ignore`.
  318. .. django-admin-option:: --no-wrap
  319. .. versionadded:: 1.3
  320. Use the ``--no-wrap`` option to disable breaking long message lines into
  321. several lines in language files.
  322. reset <appname appname ...>
  323. ---------------------------
  324. .. deprecated:: 1.3
  325. This command has been deprecated. The ``flush`` can be used to delete
  326. everything. You can also use ALTER TABLE or DROP TABLE statements manually.
  327. .. django-admin:: reset
  328. Executes the equivalent of ``sqlreset`` for the given app name(s).
  329. The :djadminopt:`--noinput` option may be provided to suppress all user
  330. prompts.
  331. .. versionadded:: 1.2
  332. The :djadminopt:`--database` option can be used to specify the alias
  333. of the database to reset.
  334. runfcgi [options]
  335. -----------------
  336. .. django-admin:: runfcgi
  337. Starts a set of FastCGI processes suitable for use with any Web server that
  338. supports the FastCGI protocol. See the :doc:`FastCGI deployment documentation
  339. </howto/deployment/fastcgi>` for details. Requires the Python FastCGI module from
  340. `flup`_.
  341. .. _flup: http://www.saddi.com/software/flup/
  342. The options accepted by this command are passed to the FastCGI library and
  343. don't use the ``'--'`` prefix as is usual for other Django management commands.
  344. .. django-admin-option:: protocol
  345. ``protocol=PROTOCOL``
  346. Protocol to use. *PROTOCOL* can be ``fcgi``, ``scgi``, ``ajp``, etc.
  347. (default is ``fcgi``)
  348. .. django-admin-option:: host
  349. ``host=HOSTNAME``
  350. Hostname to listen on.
  351. .. django-admin-option:: port
  352. ``port=PORTNUM``
  353. Port to listen on.
  354. .. django-admin-option:: socket
  355. ``socket=FILE``
  356. UNIX socket to listen on.
  357. .. django-admin-option:: method
  358. ``method=IMPL``
  359. Possible values: ``prefork`` or ``threaded`` (default ``prefork``)
  360. .. django-admin-option:: maxrequests
  361. ``maxrequests=NUMBER``
  362. Number of requests a child handles before it is killed and a new child is
  363. forked (0 means no limit).
  364. .. django-admin-option:: maxspare
  365. ``maxspare=NUMBER``
  366. Max number of spare processes / threads.
  367. .. django-admin-option:: minspare
  368. ``minspare=NUMBER``
  369. Min number of spare processes / threads.
  370. .. django-admin-option:: maxchildren
  371. ``maxchildren=NUMBER``
  372. Hard limit number of processes / threads.
  373. .. django-admin-option:: daemonize
  374. ``daemonize=BOOL``
  375. Whether to detach from terminal.
  376. .. django-admin-option:: pidfile
  377. ``pidfile=FILE``
  378. Write the spawned process-id to file *FILE*.
  379. .. django-admin-option:: workdir
  380. ``workdir=DIRECTORY``
  381. Change to directory *DIRECTORY* when daemonizing.
  382. .. django-admin-option:: debug
  383. ``debug=BOOL``
  384. Set to true to enable flup tracebacks.
  385. .. django-admin-option:: outlog
  386. ``outlog=FILE``
  387. Write stdout to the *FILE* file.
  388. .. django-admin-option:: errlog
  389. ``errlog=FILE``
  390. Write stderr to the *FILE* file.
  391. .. django-admin-option:: umask
  392. ``umask=UMASK``
  393. Umask to use when daemonizing. The value is interpeted as an octal number
  394. (default value is ``022``).
  395. Example usage::
  396. django-admin.py runfcgi socket=/tmp/fcgi.sock method=prefork daemonize=true \
  397. pidfile=/var/run/django-fcgi.pid
  398. Run a FastCGI server as a daemon and write the spawned PID in a file.
  399. runserver [port or address:port]
  400. --------------------------------
  401. .. django-admin:: runserver
  402. Starts a lightweight development Web server on the local machine. By default,
  403. the server runs on port 8000 on the IP address ``127.0.0.1``. You can pass in an
  404. IP address and port number explicitly.
  405. If you run this script as a user with normal privileges (recommended), you
  406. might not have access to start a port on a low port number. Low port numbers
  407. are reserved for the superuser (root).
  408. DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through
  409. security audits or performance tests. (And that's how it's gonna stay. We're in
  410. the business of making Web frameworks, not Web servers, so improving this
  411. server to be able to handle a production environment is outside the scope of
  412. Django.)
  413. The development server automatically reloads Python code for each request, as
  414. needed. You don't need to restart the server for code changes to take effect.
  415. When you start the server, and each time you change Python code while the
  416. server is running, the server will validate all of your installed models. (See
  417. the ``validate`` command below.) If the validator finds errors, it will print
  418. them to standard output, but it won't stop the server.
  419. You can run as many servers as you want, as long as they're on separate ports.
  420. Just execute ``django-admin.py runserver`` more than once.
  421. Note that the default IP address, ``127.0.0.1``, is not accessible from other
  422. machines on your network. To make your development server viewable to other
  423. machines on the network, use its own IP address (e.g. ``192.168.2.1``) or
  424. ``0.0.0.0`` or ``::`` (with IPv6 enabled).
  425. .. versionchanged:: 1.3
  426. You can provide an IPv6 address surrounded by brackets
  427. (e.g. ``[200a::1]:8000``). This will automatically enable IPv6 support.
  428. A hostname containing ASCII-only characters can also be used.
  429. .. django-admin-option:: --adminmedia
  430. Use the ``--adminmedia`` option to tell Django where to find the various CSS
  431. and JavaScript files for the Django admin interface. Normally, the development
  432. server serves these files out of the Django source tree magically, but you'd
  433. want to use this if you made any changes to those files for your own site.
  434. Example usage::
  435. django-admin.py runserver --adminmedia=/tmp/new-admin-style/
  436. .. versionchanged:: 1.3
  437. If the :doc:`staticfiles</ref/contrib/staticfiles>` contrib app is enabled
  438. (default in new projects) the :djadmin:`runserver` command will be overriden
  439. with an own :djadmin:`runserver<staticfiles-runserver>` command which doesn't
  440. have the :djadminopt:`--adminmedia` option due to deprecation.
  441. .. django-admin-option:: --noreload
  442. Use the ``--noreload`` option to disable the use of the auto-reloader. This
  443. means any Python code changes you make while the server is running will *not*
  444. take effect if the particular Python modules have already been loaded into
  445. memory.
  446. Example usage::
  447. django-admin.py runserver --noreload
  448. .. django-admin-option:: --ipv6, -6
  449. .. versionadded:: 1.3
  450. Use the ``--ipv6`` (or shorter ``-6``) option to tell Django to use IPv6 for
  451. the development server. This changes the default IP address from
  452. ``127.0.0.1`` to ``::1``.
  453. Example usage::
  454. django-admin.py runserver --ipv6
  455. Examples of using different ports and addresses
  456. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  457. Port 8000 on IP address ``127.0.0.1``::
  458. django-admin.py runserver
  459. Port 8000 on IP address ``1.2.3.4``::
  460. django-admin.py runserver 1.2.3.4:8000
  461. Port 7000 on IP address ``127.0.0.1``::
  462. django-admin.py runserver 7000
  463. Port 7000 on IP address ``1.2.3.4``::
  464. django-admin.py runserver 1.2.3.4:7000
  465. Port 8000 on IPv6 address ``::1``::
  466. django-admin.py runserver -6
  467. Port 7000 on IPv6 address ``::1``::
  468. django-admin.py runserver -6 7000
  469. Port 7000 on IPv6 address ``2001:0db8:1234:5678::9``::
  470. django-admin.py runserver [2001:0db8:1234:5678::9]:7000
  471. Port 8000 on IPv4 address of host ``localhost``::
  472. django-admin.py runserver localhost:8000
  473. Port 8000 on IPv6 address of host ``localhost``::
  474. django-admin.py runserver -6 localhost:8000
  475. Serving static files with the development server
  476. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  477. By default, the development server doesn't serve any static files for your site
  478. (such as CSS files, images, things under ``MEDIA_URL`` and so forth). If
  479. you want to configure Django to serve static media, read :doc:`/howto/static-files`.
  480. shell
  481. -----
  482. .. django-admin:: shell
  483. Starts the Python interactive interpreter.
  484. Django will use IPython_ or bpython_ if either is installed. If you have a
  485. rich shell installed but want to force use of the "plain" Python interpreter,
  486. use the ``--plain`` option, like so::
  487. django-admin.py shell --plain
  488. .. _IPython: http://ipython.scipy.org/
  489. .. _bpython: http://bpython-interpreter.org/
  490. sql <appname appname ...>
  491. -------------------------
  492. .. django-admin:: sql
  493. Prints the CREATE TABLE SQL statements for the given app name(s).
  494. .. versionadded:: 1.2
  495. The :djadminopt:`--database` option can be used to specify the database for
  496. which to print the SQL.
  497. sqlall <appname appname ...>
  498. ----------------------------
  499. .. django-admin:: sqlall
  500. Prints the CREATE TABLE and initial-data SQL statements for the given app name(s).
  501. Refer to the description of ``sqlcustom`` for an explanation of how to
  502. specify initial data.
  503. .. versionadded:: 1.2
  504. The :djadminopt:`--database` option can be used to specify the database for
  505. which to print the SQL.
  506. sqlclear <appname appname ...>
  507. ------------------------------
  508. .. django-admin:: sqlclear
  509. Prints the DROP TABLE SQL statements for the given app name(s).
  510. .. versionadded:: 1.2
  511. The :djadminopt:`--database` option can be used to specify the database for
  512. which to print the SQL.
  513. sqlcustom <appname appname ...>
  514. -------------------------------
  515. .. django-admin:: sqlcustom
  516. Prints the custom SQL statements for the given app name(s).
  517. For each model in each specified app, this command looks for the file
  518. ``<appname>/sql/<modelname>.sql``, where ``<appname>`` is the given app name and
  519. ``<modelname>`` is the model's name in lowercase. For example, if you have an
  520. app ``news`` that includes a ``Story`` model, ``sqlcustom`` will attempt
  521. to read a file ``news/sql/story.sql`` and append it to the output of this
  522. command.
  523. Each of the SQL files, if given, is expected to contain valid SQL. The SQL
  524. files are piped directly into the database after all of the models'
  525. table-creation statements have been executed. Use this SQL hook to make any
  526. table modifications, or insert any SQL functions into the database.
  527. Note that the order in which the SQL files are processed is undefined.
  528. .. versionadded:: 1.2
  529. The :djadminopt:`--database` option can be used to specify the database for
  530. which to print the SQL.
  531. sqlflush
  532. --------
  533. .. django-admin:: sqlflush
  534. Prints the SQL statements that would be executed for the :djadmin:`flush`
  535. command.
  536. .. versionadded:: 1.2
  537. The :djadminopt:`--database` option can be used to specify the database for
  538. which to print the SQL.
  539. sqlindexes <appname appname ...>
  540. --------------------------------
  541. .. django-admin:: sqlindexes
  542. Prints the CREATE INDEX SQL statements for the given app name(s).
  543. .. versionadded:: 1.2
  544. The :djadminopt:`--database` option can be used to specify the database for
  545. which to print the SQL.
  546. sqlreset <appname appname ...>
  547. ------------------------------
  548. .. deprecated:: 1.3
  549. This command has been deprecated. The ``sqlflush`` can be used to delete
  550. everything. You can also use ALTER TABLE or DROP TABLE statements manually.
  551. .. django-admin:: sqlreset
  552. Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given app name(s).
  553. .. versionadded:: 1.2
  554. The :djadminopt:`--database` option can be used to specify the database for
  555. which to print the SQL.
  556. sqlsequencereset <appname appname ...>
  557. --------------------------------------
  558. .. django-admin:: sqlsequencereset
  559. Prints the SQL statements for resetting sequences for the given app name(s).
  560. Sequences are indexes used by some database engines to track the next available
  561. number for automatically incremented fields.
  562. Use this command to generate SQL which will fix cases where a sequence is out
  563. of sync with its automatically incremented field data.
  564. .. versionadded:: 1.2
  565. The :djadminopt:`--database` option can be used to specify the database for
  566. which to print the SQL.
  567. startapp <appname>
  568. ------------------
  569. .. django-admin:: startapp
  570. Creates a Django app directory structure for the given app name in the current
  571. directory.
  572. startproject <projectname>
  573. --------------------------
  574. .. django-admin:: startproject
  575. Creates a Django project directory structure for the given project name in the
  576. current directory.
  577. This command is disabled when the ``--settings`` option to
  578. ``django-admin.py`` is used, or when the environment variable
  579. ``DJANGO_SETTINGS_MODULE`` has been set. To re-enable it in these
  580. situations, either omit the ``--settings`` option or unset
  581. ``DJANGO_SETTINGS_MODULE``.
  582. syncdb
  583. ------
  584. .. django-admin:: syncdb
  585. Creates the database tables for all apps in ``INSTALLED_APPS`` whose tables
  586. have not already been created.
  587. Use this command when you've added new applications to your project and want to
  588. install them in the database. This includes any apps shipped with Django that
  589. might be in ``INSTALLED_APPS`` by default. When you start a new project, run
  590. this command to install the default apps.
  591. .. admonition:: Syncdb will not alter existing tables
  592. ``syncdb`` will only create tables for models which have not yet been
  593. installed. It will *never* issue ``ALTER TABLE`` statements to match
  594. changes made to a model class after installation. Changes to model classes
  595. and database schemas often involve some form of ambiguity and, in those
  596. cases, Django would have to guess at the correct changes to make. There is
  597. a risk that critical data would be lost in the process.
  598. If you have made changes to a model and wish to alter the database tables
  599. to match, use the ``sql`` command to display the new SQL structure and
  600. compare that to your existing table schema to work out the changes.
  601. If you're installing the ``django.contrib.auth`` application, ``syncdb`` will
  602. give you the option of creating a superuser immediately.
  603. ``syncdb`` will also search for and install any fixture named ``initial_data``
  604. with an appropriate extension (e.g. ``json`` or ``xml``). See the
  605. documentation for ``loaddata`` for details on the specification of fixture
  606. data files.
  607. The :djadminopt:`--noinput` option may be provided to suppress all user
  608. prompts.
  609. .. versionadded:: 1.2
  610. The :djadminopt:`--database` option can be used to specify the database to
  611. synchronize.
  612. test <app or test identifier>
  613. -----------------------------
  614. .. django-admin:: test
  615. Runs tests for all installed models. See :doc:`/topics/testing` for more
  616. information.
  617. .. versionadded:: 1.2
  618. .. django-admin-option:: --failfast
  619. Use the :djadminopt:`--failfast` option to stop running tests and report the failure
  620. immediately after a test fails.
  621. testserver <fixture fixture ...>
  622. --------------------------------
  623. .. django-admin:: testserver
  624. Runs a Django development server (as in ``runserver``) using data from the
  625. given fixture(s).
  626. For example, this command::
  627. django-admin.py testserver mydata.json
  628. ...would perform the following steps:
  629. 1. Create a test database, as described in :doc:`/topics/testing`.
  630. 2. Populate the test database with fixture data from the given fixtures.
  631. (For more on fixtures, see the documentation for ``loaddata`` above.)
  632. 3. Runs the Django development server (as in ``runserver``), pointed at
  633. this newly created test database instead of your production database.
  634. This is useful in a number of ways:
  635. * When you're writing :doc:`unit tests </topics/testing>` of how your views
  636. act with certain fixture data, you can use ``testserver`` to interact with
  637. the views in a Web browser, manually.
  638. * Let's say you're developing your Django application and have a "pristine"
  639. copy of a database that you'd like to interact with. You can dump your
  640. database to a fixture (using the ``dumpdata`` command, explained above),
  641. then use ``testserver`` to run your Web application with that data. With
  642. this arrangement, you have the flexibility of messing up your data
  643. in any way, knowing that whatever data changes you're making are only
  644. being made to a test database.
  645. Note that this server does *not* automatically detect changes to your Python
  646. source code (as ``runserver`` does). It does, however, detect changes to
  647. templates.
  648. .. django-admin-option:: --addrport [port number or ipaddr:port]
  649. Use ``--addrport`` to specify a different port, or IP address and port, from
  650. the default of ``127.0.0.1:8000``. This value follows exactly the same format and
  651. serves exactly the same function as the argument to the ``runserver`` command.
  652. Examples:
  653. To run the test server on port 7000 with ``fixture1`` and ``fixture2``::
  654. django-admin.py testserver --addrport 7000 fixture1 fixture2
  655. django-admin.py testserver fixture1 fixture2 --addrport 7000
  656. (The above statements are equivalent. We include both of them to demonstrate
  657. that it doesn't matter whether the options come before or after the fixture
  658. arguments.)
  659. To run on 1.2.3.4:7000 with a ``test`` fixture::
  660. django-admin.py testserver --addrport 1.2.3.4:7000 test
  661. .. versionadded:: 1.3
  662. The :djadminopt:`--noinput` option may be provided to suppress all user
  663. prompts.
  664. validate
  665. --------
  666. .. django-admin:: validate
  667. Validates all installed models (according to the ``INSTALLED_APPS`` setting)
  668. and prints validation errors to standard output.
  669. Commands provided by applications
  670. =================================
  671. Some commands are only available when the ``django.contrib`` application that
  672. :doc:`implements </howto/custom-management-commands>` them has been
  673. :setting:`enabled <INSTALLED_APPS>`. This section describes them grouped by
  674. their application.
  675. ``django.contrib.auth``
  676. -----------------------
  677. changepassword
  678. ~~~~~~~~~~~~~~
  679. .. django-admin:: changepassword
  680. .. versionadded:: 1.2
  681. This command is only available if Django's :doc:`authentication system
  682. </topics/auth>` (``django.contrib.auth``) is installed.
  683. Allows changing a user's password. It prompts you to enter twice the password of
  684. the user given as parameter. If they both match, the new password will be
  685. changed immediately. If you do not supply a user, the command will attempt to
  686. change the password whose username matches the current user.
  687. Example usage::
  688. django-admin.py changepassword ringo
  689. createsuperuser
  690. ~~~~~~~~~~~~~~~
  691. .. django-admin:: createsuperuser
  692. This command is only available if Django's :doc:`authentication system
  693. </topics/auth>` (``django.contrib.auth``) is installed.
  694. Creates a superuser account (a user who has all permissions). This is
  695. useful if you need to create an initial superuser account but did not
  696. do so during ``syncdb``, or if you need to programmatically generate
  697. superuser accounts for your site(s).
  698. When run interactively, this command will prompt for a password for
  699. the new superuser account. When run non-interactively, no password
  700. will be set, and the superuser account will not be able to log in until
  701. a password has been manually set for it.
  702. .. django-admin-option:: --username
  703. .. django-admin-option:: --email
  704. The username and email address for the new account can be supplied by
  705. using the ``--username`` and ``--email`` arguments on the command
  706. line. If either of those is not supplied, ``createsuperuser`` will prompt for
  707. it when running interactively.
  708. ``django.contrib.gis``
  709. ----------------------
  710. ogrinspect
  711. ~~~~~~~~~~
  712. This command is only available if :doc:`GeoDjango </ref/contrib/gis/index>`
  713. (``django.contrib.gis``) is installed.
  714. Please refer to its :djadmin:`description <ogrinspect>` in the GeoDjango
  715. documentation.
  716. ``django.contrib.sitemaps``
  717. ---------------------------
  718. ping_google
  719. ~~~~~~~~~~~
  720. This command is only available if the :doc:`Sitemaps framework
  721. </ref/contrib/sitemaps>` (``django.contrib.sitemaps``) is installed.
  722. Please refer to its :djadmin:`description <ping_google>` in the Sitemaps
  723. documentation.
  724. ``django.contrib.staticfiles``
  725. ------------------------------
  726. collectstatic
  727. ~~~~~~~~~~~~~
  728. This command is only available if the :doc:`static files application
  729. </howto/static-files>` (``django.contrib.staticfiles``) is installed.
  730. Please refer to its :djadmin:`description <collectstatic>` in the
  731. :doc:`staticfiles </ref/contrib/staticfiles>` documentation.
  732. findstatic
  733. ~~~~~~~~~~
  734. This command is only available if the :doc:`static files application
  735. </howto/static-files>` (``django.contrib.staticfiles``) is installed.
  736. Please refer to its :djadmin:`description <findstatic>` in the :doc:`staticfiles
  737. </ref/contrib/staticfiles>` documentation.
  738. Default options
  739. ===============
  740. Although some commands may allow their own custom options, every command
  741. allows for the following options:
  742. .. django-admin-option:: --pythonpath
  743. Example usage::
  744. django-admin.py syncdb --pythonpath='/home/djangoprojects/myproject'
  745. Adds the given filesystem path to the Python `import search path`_. If this
  746. isn't provided, ``django-admin.py`` will use the ``PYTHONPATH`` environment
  747. variable.
  748. Note that this option is unnecessary in ``manage.py``, because it takes care of
  749. setting the Python path for you.
  750. .. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html
  751. .. django-admin-option:: --settings
  752. Example usage::
  753. django-admin.py syncdb --settings=mysite.settings
  754. Explicitly specifies the settings module to use. The settings module should be
  755. in Python package syntax, e.g. ``mysite.settings``. If this isn't provided,
  756. ``django-admin.py`` will use the ``DJANGO_SETTINGS_MODULE`` environment
  757. variable.
  758. Note that this option is unnecessary in ``manage.py``, because it uses
  759. ``settings.py`` from the current project by default.
  760. .. django-admin-option:: --traceback
  761. Example usage::
  762. django-admin.py syncdb --traceback
  763. By default, ``django-admin.py`` will show a simple error message whenever an
  764. error occurs. If you specify ``--traceback``, ``django-admin.py`` will
  765. output a full stack trace whenever an exception is raised.
  766. .. django-admin-option:: --verbosity
  767. Example usage::
  768. django-admin.py syncdb --verbosity 2
  769. Use ``--verbosity`` to specify the amount of notification and debug information
  770. that ``django-admin.py`` should print to the console.
  771. * ``0`` means no output.
  772. * ``1`` means normal output (default).
  773. * ``2`` means verbose output.
  774. * ``3`` means *very* verbose output.
  775. Common options
  776. ==============
  777. The following options are not available on every commands, but they are
  778. common to a number of commands.
  779. .. django-admin-option:: --database
  780. .. versionadded:: 1.2
  781. Used to specify the database on which a command will operate. If not
  782. specified, this option will default to an alias of ``default``.
  783. For example, to dump data from the database with the alias ``master``::
  784. django-admin.py dumpdata --database=master
  785. .. django-admin-option:: --exclude
  786. Exclude a specific application from the applications whose contents is
  787. output. For example, to specifically exclude the `auth` application from
  788. the output of dumpdata, you would call::
  789. django-admin.py dumpdata --exclude=auth
  790. If you want to exclude multiple applications, use multiple ``--exclude``
  791. directives::
  792. django-admin.py dumpdata --exclude=auth --exclude=contenttypes
  793. .. django-admin-option:: --locale
  794. Use the ``--locale`` or ``-l`` option to specify the locale to process.
  795. If not provided all locales are processed.
  796. .. django-admin-option:: --noinput
  797. Use the ``--noinput`` option to suppress all user prompting, such as "Are
  798. you sure?" confirmation messages. This is useful if ``django-admin.py`` is
  799. being executed as an unattended, automated script.
  800. Extra niceties
  801. ==============
  802. .. _syntax-coloring:
  803. Syntax coloring
  804. ---------------
  805. The ``django-admin.py`` / ``manage.py`` commands will use pretty
  806. color-coded output if your terminal supports ANSI-colored output. It
  807. won't use the color codes if you're piping the command's output to
  808. another program.
  809. The colors used for syntax highlighting can be customized. Django
  810. ships with three color palettes:
  811. * ``dark``, suited to terminals that show white text on a black
  812. background. This is the default palette.
  813. * ``light``, suited to terminals that show black text on a white
  814. background.
  815. * ``nocolor``, which disables syntax highlighting.
  816. You select a palette by setting a ``DJANGO_COLORS`` environment
  817. variable to specify the palette you want to use. For example, to
  818. specify the ``light`` palette under a Unix or OS/X BASH shell, you
  819. would run the following at a command prompt::
  820. export DJANGO_COLORS="light"
  821. You can also customize the colors that are used. Django specifies a
  822. number of roles in which color is used:
  823. * ``error`` - A major error.
  824. * ``notice`` - A minor error.
  825. * ``sql_field`` - The name of a model field in SQL.
  826. * ``sql_coltype`` - The type of a model field in SQL.
  827. * ``sql_keyword`` - A SQL keyword.
  828. * ``sql_table`` - The name of a model in SQL.
  829. * ``http_info`` - A 1XX HTTP Informational server response.
  830. * ``http_success`` - A 2XX HTTP Success server response.
  831. * ``http_not_modified`` - A 304 HTTP Not Modified server response.
  832. * ``http_redirect`` - A 3XX HTTP Redirect server response other than 304.
  833. * ``http_not_found`` - A 404 HTTP Not Found server response.
  834. * ``http_bad_request`` - A 4XX HTTP Bad Request server response other than 404.
  835. * ``http_server_error`` - A 5XX HTTP Server Error response.
  836. Each of these roles can be assigned a specific foreground and
  837. background color, from the following list:
  838. * ``black``
  839. * ``red``
  840. * ``green``
  841. * ``yellow``
  842. * ``blue``
  843. * ``magenta``
  844. * ``cyan``
  845. * ``white``
  846. Each of these colors can then be modified by using the following
  847. display options:
  848. * ``bold``
  849. * ``underscore``
  850. * ``blink``
  851. * ``reverse``
  852. * ``conceal``
  853. A color specification follows one of the following patterns:
  854. * ``role=fg``
  855. * ``role=fg/bg``
  856. * ``role=fg,option,option``
  857. * ``role=fg/bg,option,option``
  858. where ``role`` is the name of a valid color role, ``fg`` is the
  859. foreground color, ``bg`` is the background color and each ``option``
  860. is one of the color modifying options. Multiple color specifications
  861. are then separated by semicolon. For example::
  862. export DJANGO_COLORS="error=yellow/blue,blink;notice=magenta"
  863. would specify that errors be displayed using blinking yellow on blue,
  864. and notices displayed using magenta. All other color roles would be
  865. left uncolored.
  866. Colors can also be specified by extending a base palette. If you put
  867. a palette name in a color specification, all the colors implied by that
  868. palette will be loaded. So::
  869. export DJANGO_COLORS="light;error=yellow/blue,blink;notice=magenta"
  870. would specify the use of all the colors in the light color palette,
  871. *except* for the colors for errors and notices which would be
  872. overridden as specified.
  873. Bash completion
  874. ---------------
  875. If you use the Bash shell, consider installing the Django bash completion
  876. script, which lives in ``extras/django_bash_completion`` in the Django
  877. distribution. It enables tab-completion of ``django-admin.py`` and
  878. ``manage.py`` commands, so you can, for instance...
  879. * Type ``django-admin.py``.
  880. * Press [TAB] to see all available options.
  881. * Type ``sql``, then [TAB], to see all available options whose names start
  882. with ``sql``.
  883. See :doc:`/howto/custom-management-commands` for how to add customized actions.
  884. ==========================================
  885. Running management commands from your code
  886. ==========================================
  887. .. function:: django.core.management.call_command(name, *args, **options)
  888. To call a management command from code use ``call_command``.
  889. ``name``
  890. the name of the command to call.
  891. ``*args``
  892. a list of arguments accepted by the command.
  893. ``**options``
  894. named options accepted on the command-line.
  895. Examples::
  896. from django.core import management
  897. management.call_command('flush', verbosity=0, interactive=False)
  898. management.call_command('loaddata', 'test_data', verbosity=0)