django-admin.txt 51 KB

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