django-admin.txt 51 KB

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