django-admin.txt 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. ==================================
  2. ``django-admin`` and ``manage.py``
  3. ==================================
  4. ``django-admin`` 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. It
  7. does the same thing as ``django-admin`` but also sets the
  8. :envvar:`DJANGO_SETTINGS_MODULE` environment variable so that it points to your
  9. project's ``settings.py`` file.
  10. The ``django-admin`` script should be on your system path if you installed
  11. Django via its ``setup.py`` utility. If it's not on your path, you can find it
  12. in ``site-packages/django/bin`` within your Python installation. Consider
  13. symlinking it from some place on your path, such as ``/usr/local/bin``.
  14. For Windows users, who do not have symlinking functionality available, you can
  15. copy ``django-admin.exe`` to a location on your existing path or edit the
  16. ``PATH`` settings (under ``Settings - Control Panel - System - Advanced -
  17. Environment...``) to point to its installed location.
  18. Generally, when working on a single Django project, it's easier to use
  19. ``manage.py`` than ``django-admin``. If you need to switch between multiple
  20. Django settings files, use ``django-admin`` with
  21. :envvar:`DJANGO_SETTINGS_MODULE` or the :option:`--settings` command line
  22. option.
  23. The command-line examples throughout this document use ``django-admin`` to
  24. be consistent, but any example can use ``manage.py`` or ``python -m django``
  25. just as well.
  26. Usage
  27. =====
  28. .. console::
  29. $ django-admin <command> [options]
  30. $ manage.py <command> [options]
  31. $ python -m django <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 help`` to display usage information and a list of the
  39. commands provided by each application.
  40. Run ``django-admin help --commands`` to display a list of all available
  41. commands.
  42. Run ``django-admin 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 version`` to display the current Django version.
  53. The output follows the schema described in :pep:`440`::
  54. 1.4.dev17026
  55. 1.4a1
  56. 1.4
  57. Displaying debug output
  58. -----------------------
  59. .. program:: None
  60. Use :option:`--verbosity` to specify the amount of notification and debug
  61. information that ``django-admin`` prints to the console.
  62. Available commands
  63. ==================
  64. ``check``
  65. ---------
  66. .. django-admin:: check [app_label [app_label ...]]
  67. Uses the :doc:`system check framework </ref/checks>` to inspect the entire
  68. Django project for common problems.
  69. By default, all apps will be checked. You can check a subset of apps by
  70. providing a list of app labels as arguments::
  71. django-admin check auth admin myapp
  72. If you do not specify any app, all apps will be checked.
  73. .. django-admin-option:: --tag TAGS, -t TAGS
  74. The system check framework performs many different types of checks that are
  75. :ref:`categorized with tags <system-check-builtin-tags>`. You can use these
  76. tags to restrict the checks performed to just those in a particular category.
  77. For example, to perform only models and compatibility checks, run::
  78. django-admin check --tag models --tag compatibility
  79. .. django-admin-option:: --list-tags
  80. Lists all available tags.
  81. .. django-admin-option:: --deploy
  82. Activates some additional checks that are only relevant in a deployment setting.
  83. You can use this option in your local development environment, but since your
  84. local development settings module may not have many of your production settings,
  85. you will probably want to point the ``check`` command at a different settings
  86. module, either by setting the ``DJANGO_SETTINGS_MODULE`` environment variable,
  87. or by passing the ``--settings`` option::
  88. django-admin check --deploy --settings=production_settings
  89. Or you could run it directly on a production or staging deployment to verify
  90. that the correct settings are in use (omitting ``--settings``). You could even
  91. make it part of your integration test suite.
  92. .. django-admin-option:: --fail-level {CRITICAL,ERROR,WARNING,INFO,DEBUG}
  93. Specifies the message level that will cause the command to exit with a non-zero
  94. status. Default is ``ERROR``.
  95. ``compilemessages``
  96. -------------------
  97. .. django-admin:: compilemessages
  98. Compiles ``.po`` files created by :djadmin:`makemessages` to ``.mo`` files for
  99. use with the built-in gettext support. See :doc:`/topics/i18n/index`.
  100. .. django-admin-option:: --locale LOCALE, -l LOCALE
  101. Specifies the locale(s) to process. If not provided, all locales are processed.
  102. .. django-admin-option:: --exclude EXCLUDE, -x EXCLUDE
  103. Specifies the locale(s) to exclude from processing. If not provided, no locales
  104. are excluded.
  105. .. django-admin-option:: --use-fuzzy, -f
  106. Includes fuzzy translations into compiled files.
  107. Example usage::
  108. django-admin compilemessages --locale=pt_BR
  109. django-admin compilemessages --locale=pt_BR --locale=fr -f
  110. django-admin compilemessages -l pt_BR
  111. django-admin compilemessages -l pt_BR -l fr --use-fuzzy
  112. django-admin compilemessages --exclude=pt_BR
  113. django-admin compilemessages --exclude=pt_BR --exclude=fr
  114. django-admin compilemessages -x pt_BR
  115. django-admin compilemessages -x pt_BR -x fr
  116. .. django-admin-option:: --ignore PATTERN, -i PATTERN
  117. .. versionadded:: 3.0
  118. Ignores directories matching the given :mod:`glob`-style pattern. Use
  119. multiple times to ignore more.
  120. Example usage::
  121. django-admin compilemessages --ignore=cache --ignore=outdated/*/locale
  122. ``createcachetable``
  123. --------------------
  124. .. django-admin:: createcachetable
  125. Creates the cache tables for use with the database cache backend using the
  126. information from your settings file. See :doc:`/topics/cache` for more
  127. information.
  128. .. django-admin-option:: --database DATABASE
  129. Specifies the database in which the cache table(s) will be created. Defaults to
  130. ``default``.
  131. .. django-admin-option:: --dry-run
  132. Prints the SQL that would be run without actually running it, so you can
  133. customize it or use the migrations framework.
  134. ``dbshell``
  135. -----------
  136. .. django-admin:: dbshell
  137. Runs the command-line client for the database engine specified in your
  138. :setting:`ENGINE <DATABASE-ENGINE>` setting, with the connection parameters
  139. specified in your :setting:`USER`, :setting:`PASSWORD`, etc., settings.
  140. * For PostgreSQL, this runs the ``psql`` command-line client.
  141. * For MySQL, this runs the ``mysql`` command-line client.
  142. * For SQLite, this runs the ``sqlite3`` command-line client.
  143. * For Oracle, this runs the ``sqlplus`` command-line client.
  144. This command assumes the programs are on your ``PATH`` so that a simple call to
  145. the program name (``psql``, ``mysql``, ``sqlite3``, ``sqlplus``) will find the
  146. program in the right place. There's no way to specify the location of the
  147. program manually.
  148. .. django-admin-option:: --database DATABASE
  149. Specifies the database onto which to open a shell. Defaults to ``default``.
  150. ``diffsettings``
  151. ----------------
  152. .. django-admin:: diffsettings
  153. Displays differences between the current settings file and Django's default
  154. settings (or another settings file specified by :option:`--default`).
  155. Settings that don't appear in the defaults are followed by ``"###"``. For
  156. example, the default settings don't define :setting:`ROOT_URLCONF`, so
  157. :setting:`ROOT_URLCONF` is followed by ``"###"`` in the output of
  158. ``diffsettings``.
  159. .. django-admin-option:: --all
  160. Displays all settings, even if they have Django's default value. Such settings
  161. are prefixed by ``"###"``.
  162. .. django-admin-option:: --default MODULE
  163. The settings module to compare the current settings against. Leave empty to
  164. compare against Django's default settings.
  165. .. django-admin-option:: --output {hash,unified}
  166. Specifies the output format. Available values are ``hash`` and ``unified``.
  167. ``hash`` is the default mode that displays the output that's described above.
  168. ``unified`` displays the output similar to ``diff -u``. Default settings are
  169. prefixed with a minus sign, followed by the changed setting prefixed with a
  170. plus sign.
  171. ``dumpdata``
  172. ------------
  173. .. django-admin:: dumpdata [app_label[.ModelName] [app_label[.ModelName] ...]]
  174. Outputs to standard output all data in the database associated with the named
  175. application(s).
  176. If no application name is provided, all installed applications will be dumped.
  177. The output of ``dumpdata`` can be used as input for :djadmin:`loaddata`.
  178. Note that ``dumpdata`` uses the default manager on the model for selecting the
  179. records to dump. If you're using a :ref:`custom manager <custom-managers>` as
  180. the default manager and it filters some of the available records, not all of the
  181. objects will be dumped.
  182. .. django-admin-option:: --all, -a
  183. Uses Django's base manager, dumping records which might otherwise be filtered
  184. or modified by a custom manager.
  185. .. django-admin-option:: --format FORMAT
  186. Specifies the serialization format of the output. Defaults to JSON. Supported
  187. formats are listed in :ref:`serialization-formats`.
  188. .. django-admin-option:: --indent INDENT
  189. Specifies the number of indentation spaces to use in the output. Defaults to
  190. ``None`` which displays all data on single line.
  191. .. django-admin-option:: --exclude EXCLUDE, -e EXCLUDE
  192. Prevents specific applications or models (specified in the form of
  193. ``app_label.ModelName``) from being dumped. If you specify a model name, the
  194. output will be restricted to that model, rather than the entire application.
  195. You can also mix application names and model names.
  196. If you want to exclude multiple applications, pass ``--exclude`` more than
  197. once::
  198. django-admin dumpdata --exclude=auth --exclude=contenttypes
  199. .. django-admin-option:: --database DATABASE
  200. Specifies the database from which data will be dumped. Defaults to ``default``.
  201. .. django-admin-option:: --natural-foreign
  202. Uses the ``natural_key()`` model method to serialize any foreign key and
  203. many-to-many relationship to objects of the type that defines the method. If
  204. you're dumping ``contrib.auth`` ``Permission`` objects or
  205. ``contrib.contenttypes`` ``ContentType`` objects, you should probably use this
  206. flag. See the :ref:`natural keys <topics-serialization-natural-keys>`
  207. documentation for more details on this and the next option.
  208. .. django-admin-option:: --natural-primary
  209. Omits the primary key in the serialized data of this object since it can be
  210. calculated during deserialization.
  211. .. django-admin-option:: --pks PRIMARY_KEYS
  212. Outputs only the objects specified by a comma separated list of primary keys.
  213. This is only available when dumping one model. By default, all the records of
  214. the model are output.
  215. .. django-admin-option:: --output OUTPUT, -o OUTPUT
  216. Specifies a file to write the serialized data to. By default, the data goes to
  217. standard output.
  218. When this option is set and ``--verbosity`` is greater than 0 (the default), a
  219. progress bar is shown in the terminal.
  220. ``flush``
  221. ---------
  222. .. django-admin:: flush
  223. Removes all data from the database and re-executes any post-synchronization
  224. handlers. The table of which migrations have been applied is not cleared.
  225. If you would rather start from an empty database and re-run all migrations, you
  226. should drop and recreate the database and then run :djadmin:`migrate` instead.
  227. .. django-admin-option:: --noinput, --no-input
  228. Suppresses all user prompts.
  229. .. django-admin-option:: --database DATABASE
  230. Specifies the database to flush. Defaults to ``default``.
  231. ``inspectdb``
  232. -------------
  233. .. django-admin:: inspectdb [table [table ...]]
  234. Introspects the database tables in the database pointed-to by the
  235. :setting:`NAME` setting and outputs a Django model module (a ``models.py``
  236. file) to standard output.
  237. You may choose what tables or views to inspect by passing their names as
  238. arguments. If no arguments are provided, models are created for views only if
  239. the :option:`--include-views` option is used. Models for partition tables are
  240. created on PostgreSQL if the :option:`--include-partitions` option is used.
  241. Use this if you have a legacy database with which you'd like to use Django.
  242. The script will inspect the database and create a model for each table within
  243. it.
  244. As you might expect, the created models will have an attribute for every field
  245. in the table. Note that ``inspectdb`` has a few special cases in its field-name
  246. output:
  247. * If ``inspectdb`` cannot map a column's type to a model field type, it'll
  248. use ``TextField`` and will insert the Python comment
  249. ``'This field type is a guess.'`` next to the field in the generated
  250. model. The recognized fields may depend on apps listed in
  251. :setting:`INSTALLED_APPS`. For example, :mod:`django.contrib.postgres` adds
  252. recognition for several PostgreSQL-specific field types.
  253. * If the database column name is a Python reserved word (such as
  254. ``'pass'``, ``'class'`` or ``'for'``), ``inspectdb`` will append
  255. ``'_field'`` to the attribute name. For example, if a table has a column
  256. ``'for'``, the generated model will have a field ``'for_field'``, with
  257. the ``db_column`` attribute set to ``'for'``. ``inspectdb`` will insert
  258. the Python comment
  259. ``'Field renamed because it was a Python reserved word.'`` next to the
  260. field.
  261. This feature is meant as a shortcut, not as definitive model generation. After
  262. you run it, you'll want to look over the generated models yourself to make
  263. customizations. In particular, you'll need to rearrange models' order, so that
  264. models that refer to other models are ordered properly.
  265. Django doesn't create database defaults when a
  266. :attr:`~django.db.models.Field.default` is specified on a model field.
  267. Similarly, database defaults aren't translated to model field defaults or
  268. detected in any fashion by ``inspectdb``.
  269. By default, ``inspectdb`` creates unmanaged models. That is, ``managed = False``
  270. in the model's ``Meta`` class tells Django not to manage each table's creation,
  271. modification, and deletion. If you do want to allow Django to manage the
  272. table's lifecycle, you'll need to change the
  273. :attr:`~django.db.models.Options.managed` option to ``True`` (or simply remove
  274. it because ``True`` is its default value).
  275. Database-specific notes
  276. ~~~~~~~~~~~~~~~~~~~~~~~
  277. Oracle
  278. ^^^^^^
  279. * Models are created for materialized views if :option:`--include-views` is
  280. used.
  281. PostgreSQL
  282. ^^^^^^^^^^
  283. * Models are created for foreign tables.
  284. * Models are created for materialized views if
  285. :option:`--include-views` is used.
  286. * Models are created for partition tables if
  287. :option:`--include-partitions` is used.
  288. .. versionchanged:: 2.2
  289. Support for foreign tables and materialized views was added.
  290. .. django-admin-option:: --database DATABASE
  291. Specifies the database to introspect. Defaults to ``default``.
  292. .. django-admin-option:: --include-partitions
  293. .. versionadded:: 2.2
  294. If this option is provided, models are also created for partitions.
  295. Only support for PostgreSQL is implemented.
  296. .. django-admin-option:: --include-views
  297. If this option is provided, models are also created for database views.
  298. ``loaddata``
  299. ------------
  300. .. django-admin:: loaddata fixture [fixture ...]
  301. Searches for and loads the contents of the named fixture into the database.
  302. .. django-admin-option:: --database DATABASE
  303. Specifies the database into which the data will be loaded. Defaults to
  304. ``default``.
  305. .. django-admin-option:: --ignorenonexistent, -i
  306. Ignores fields and models that may have been removed since the fixture was
  307. originally generated.
  308. .. django-admin-option:: --app APP_LABEL
  309. Specifies a single app to look for fixtures in rather than looking in all apps.
  310. .. django-admin-option:: --format FORMAT
  311. Specifies the :ref:`serialization format <serialization-formats>` (e.g.,
  312. ``json`` or ``xml``) for fixtures :ref:`read from stdin
  313. <loading-fixtures-stdin>`.
  314. .. django-admin-option:: --exclude EXCLUDE, -e EXCLUDE
  315. Excludes loading the fixtures from the given applications and/or models (in the
  316. form of ``app_label`` or ``app_label.ModelName``). Use the option multiple
  317. times to exclude more than one app or model.
  318. What's a "fixture"?
  319. ~~~~~~~~~~~~~~~~~~~
  320. A *fixture* is a collection of files that contain the serialized contents of
  321. the database. Each fixture has a unique name, and the files that comprise the
  322. fixture can be distributed over multiple directories, in multiple applications.
  323. Django will search in three locations for fixtures:
  324. 1. In the ``fixtures`` directory of every installed application
  325. 2. In any directory named in the :setting:`FIXTURE_DIRS` setting
  326. 3. In the literal path named by the fixture
  327. Django will load any and all fixtures it finds in these locations that match
  328. the provided fixture names.
  329. If the named fixture has a file extension, only fixtures of that type
  330. will be loaded. For example::
  331. django-admin loaddata mydata.json
  332. would only load JSON fixtures called ``mydata``. The fixture extension
  333. must correspond to the registered name of a
  334. :ref:`serializer <serialization-formats>` (e.g., ``json`` or ``xml``).
  335. If you omit the extensions, Django will search all available fixture types
  336. for a matching fixture. For example::
  337. django-admin loaddata mydata
  338. would look for any fixture of any fixture type called ``mydata``. If a fixture
  339. directory contained ``mydata.json``, that fixture would be loaded
  340. as a JSON fixture.
  341. The fixtures that are named can include directory components. These
  342. directories will be included in the search path. For example::
  343. django-admin loaddata foo/bar/mydata.json
  344. would search ``<app_label>/fixtures/foo/bar/mydata.json`` for each installed
  345. application, ``<dirname>/foo/bar/mydata.json`` for each directory in
  346. :setting:`FIXTURE_DIRS`, and the literal path ``foo/bar/mydata.json``.
  347. When fixture files are processed, the data is saved to the database as is.
  348. Model defined :meth:`~django.db.models.Model.save` methods are not called, and
  349. any :data:`~django.db.models.signals.pre_save` or
  350. :data:`~django.db.models.signals.post_save` signals will be called with
  351. ``raw=True`` since the instance only contains attributes that are local to the
  352. model. You may, for example, want to disable handlers that access
  353. related fields that aren't present during fixture loading and would otherwise
  354. raise an exception::
  355. from django.db.models.signals import post_save
  356. from .models import MyModel
  357. def my_handler(**kwargs):
  358. # disable the handler during fixture loading
  359. if kwargs['raw']:
  360. return
  361. ...
  362. post_save.connect(my_handler, sender=MyModel)
  363. You could also write a simple decorator to encapsulate this logic::
  364. from functools import wraps
  365. def disable_for_loaddata(signal_handler):
  366. """
  367. Decorator that turns off signal handlers when loading fixture data.
  368. """
  369. @wraps(signal_handler)
  370. def wrapper(*args, **kwargs):
  371. if kwargs['raw']:
  372. return
  373. signal_handler(*args, **kwargs)
  374. return wrapper
  375. @disable_for_loaddata
  376. def my_handler(**kwargs):
  377. ...
  378. Just be aware that this logic will disable the signals whenever fixtures are
  379. deserialized, not just during ``loaddata``.
  380. Note that the order in which fixture files are processed is undefined. However,
  381. all fixture data is installed as a single transaction, so data in
  382. one fixture can reference data in another fixture. If the database backend
  383. supports row-level constraints, these constraints will be checked at the
  384. end of the transaction.
  385. The :djadmin:`dumpdata` command can be used to generate input for ``loaddata``.
  386. Compressed fixtures
  387. ~~~~~~~~~~~~~~~~~~~
  388. Fixtures may be compressed in ``zip``, ``gz``, or ``bz2`` format. For example::
  389. django-admin loaddata mydata.json
  390. would look for any of ``mydata.json``, ``mydata.json.zip``,
  391. ``mydata.json.gz``, or ``mydata.json.bz2``. The first file contained within a
  392. zip-compressed archive is used.
  393. Note that if two fixtures with the same name but different
  394. fixture type are discovered (for example, if ``mydata.json`` and
  395. ``mydata.xml.gz`` were found in the same fixture directory), fixture
  396. installation will be aborted, and any data installed in the call to
  397. ``loaddata`` will be removed from the database.
  398. .. admonition:: MySQL with MyISAM and fixtures
  399. The MyISAM storage engine of MySQL doesn't support transactions or
  400. constraints, so if you use MyISAM, you won't get validation of fixture
  401. data, or a rollback if multiple transaction files are found.
  402. Database-specific fixtures
  403. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  404. If you're in a multi-database setup, you might have fixture data that
  405. you want to load onto one database, but not onto another. In this
  406. situation, you can add a database identifier into the names of your fixtures.
  407. For example, if your :setting:`DATABASES` setting has a 'master' database
  408. defined, name the fixture ``mydata.master.json`` or
  409. ``mydata.master.json.gz`` and the fixture will only be loaded when you
  410. specify you want to load data into the ``master`` database.
  411. .. _loading-fixtures-stdin:
  412. Loading fixtures from ``stdin``
  413. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  414. You can use a dash as the fixture name to load input from ``sys.stdin``. For
  415. example::
  416. django-admin loaddata --format=json -
  417. When reading from ``stdin``, the :option:`--format <loaddata --format>` option
  418. is required to specify the :ref:`serialization format <serialization-formats>`
  419. of the input (e.g., ``json`` or ``xml``).
  420. Loading from ``stdin`` is useful with standard input and output redirections.
  421. For example::
  422. django-admin dumpdata --format=json --database=test app_label.ModelName | django-admin loaddata --format=json --database=prod -
  423. ``makemessages``
  424. ----------------
  425. .. django-admin:: makemessages
  426. Runs over the entire source tree of the current directory and pulls out all
  427. strings marked for translation. It creates (or updates) a message file in the
  428. conf/locale (in the Django tree) or locale (for project and application)
  429. directory. After making changes to the messages files you need to compile them
  430. with :djadmin:`compilemessages` for use with the builtin gettext support. See
  431. the :ref:`i18n documentation <how-to-create-language-files>` for details.
  432. This command doesn't require configured settings. However, when settings aren't
  433. configured, the command can't ignore the :setting:`MEDIA_ROOT` and
  434. :setting:`STATIC_ROOT` directories or include :setting:`LOCALE_PATHS`.
  435. .. django-admin-option:: --all, -a
  436. Updates the message files for all available languages.
  437. .. django-admin-option:: --extension EXTENSIONS, -e EXTENSIONS
  438. Specifies a list of file extensions to examine (default: ``html``, ``txt``,
  439. ``py`` or ``js`` if :option:`--domain` is ``js``).
  440. Example usage::
  441. django-admin makemessages --locale=de --extension xhtml
  442. Separate multiple extensions with commas or use ``-e`` or ``--extension``
  443. multiple times::
  444. django-admin makemessages --locale=de --extension=html,txt --extension xml
  445. .. django-admin-option:: --locale LOCALE, -l LOCALE
  446. Specifies the locale(s) to process.
  447. .. django-admin-option:: --exclude EXCLUDE, -x EXCLUDE
  448. Specifies the locale(s) to exclude from processing. If not provided, no locales
  449. are excluded.
  450. Example usage::
  451. django-admin makemessages --locale=pt_BR
  452. django-admin makemessages --locale=pt_BR --locale=fr
  453. django-admin makemessages -l pt_BR
  454. django-admin makemessages -l pt_BR -l fr
  455. django-admin makemessages --exclude=pt_BR
  456. django-admin makemessages --exclude=pt_BR --exclude=fr
  457. django-admin makemessages -x pt_BR
  458. django-admin makemessages -x pt_BR -x fr
  459. .. django-admin-option:: --domain DOMAIN, -d DOMAIN
  460. Specifies the domain of the messages files. Supported options are:
  461. * ``django`` for all ``*.py``, ``*.html`` and ``*.txt`` files (default)
  462. * ``djangojs`` for ``*.js`` files
  463. .. django-admin-option:: --symlinks, -s
  464. Follows symlinks to directories when looking for new translation strings.
  465. Example usage::
  466. django-admin makemessages --locale=de --symlinks
  467. .. django-admin-option:: --ignore PATTERN, -i PATTERN
  468. Ignores files or directories matching the given :mod:`glob`-style pattern. Use
  469. multiple times to ignore more.
  470. These patterns are used by default: ``'CVS'``, ``'.*'``, ``'*~'``, ``'*.pyc'``.
  471. Example usage::
  472. django-admin makemessages --locale=en_US --ignore=apps/* --ignore=secret/*.html
  473. .. django-admin-option:: --no-default-ignore
  474. Disables the default values of ``--ignore``.
  475. .. django-admin-option:: --no-wrap
  476. Disables breaking long message lines into several lines in language files.
  477. .. django-admin-option:: --no-location
  478. Suppresses writing '``#: filename:line``’ comment lines in language files.
  479. Using this option makes it harder for technically skilled translators to
  480. understand each message's context.
  481. .. django-admin-option:: --add-location [{full,file,never}]
  482. Controls ``#: filename:line`` comment lines in language files. If the option
  483. is:
  484. * ``full`` (the default if not given): the lines include both file name and
  485. line number.
  486. * ``file``: the line number is omitted.
  487. * ``never``: the lines are suppressed (same as :option:`--no-location`).
  488. Requires ``gettext`` 0.19 or newer.
  489. .. django-admin-option:: --keep-pot
  490. Prevents deleting the temporary ``.pot`` files generated before creating the
  491. ``.po`` file. This is useful for debugging errors which may prevent the final
  492. language files from being created.
  493. .. seealso::
  494. See :ref:`customizing-makemessages` for instructions on how to customize
  495. the keywords that :djadmin:`makemessages` passes to ``xgettext``.
  496. ``makemigrations``
  497. ------------------
  498. .. django-admin:: makemigrations [app_label [app_label ...]]
  499. Creates new migrations based on the changes detected to your models.
  500. Migrations, their relationship with apps and more are covered in depth in
  501. :doc:`the migrations documentation</topics/migrations>`.
  502. Providing one or more app names as arguments will limit the migrations created
  503. to the app(s) specified and any dependencies needed (the table at the other end
  504. of a ``ForeignKey``, for example).
  505. To add migrations to an app that doesn't have a ``migrations`` directory, run
  506. ``makemigrations`` with the app's ``app_label``.
  507. .. django-admin-option:: --noinput, --no-input
  508. Suppresses all user prompts. If a suppressed prompt cannot be resolved
  509. automatically, the command will exit with error code 3.
  510. .. django-admin-option:: --empty
  511. Outputs an empty migration for the specified apps, for manual editing. This is
  512. for advanced users and should not be used unless you are familiar with the
  513. migration format, migration operations, and the dependencies between your
  514. migrations.
  515. .. django-admin-option:: --dry-run
  516. Shows what migrations would be made without actually writing any migrations
  517. files to disk. Using this option along with ``--verbosity 3`` will also show
  518. the complete migrations files that would be written.
  519. .. django-admin-option:: --merge
  520. Enables fixing of migration conflicts.
  521. .. django-admin-option:: --name NAME, -n NAME
  522. Allows naming the generated migration(s) instead of using a generated name. The
  523. name must be a valid Python :ref:`identifier <python:identifiers>`.
  524. .. django-admin-option:: --no-header
  525. .. versionadded:: 2.2
  526. Generate migration files without Django version and timestamp header.
  527. .. django-admin-option:: --check
  528. Makes ``makemigrations`` exit with a non-zero status when model changes without
  529. migrations are detected.
  530. ``migrate``
  531. -----------
  532. .. django-admin:: migrate [app_label] [migration_name]
  533. Synchronizes the database state with the current set of models and migrations.
  534. Migrations, their relationship with apps and more are covered in depth in
  535. :doc:`the migrations documentation</topics/migrations>`.
  536. The behavior of this command changes depending on the arguments provided:
  537. * No arguments: All apps have all of their migrations run.
  538. * ``<app_label>``: The specified app has its migrations run, up to the most
  539. recent migration. This may involve running other apps' migrations too, due
  540. to dependencies.
  541. * ``<app_label> <migrationname>``: Brings the database schema to a state where
  542. the named migration is applied, but no later migrations in the same app are
  543. applied. This may involve unapplying migrations if you have previously
  544. migrated past the named migration. Use the name ``zero`` to unapply all
  545. migrations for an app.
  546. .. django-admin-option:: --database DATABASE
  547. Specifies the database to migrate. Defaults to ``default``.
  548. .. django-admin-option:: --fake
  549. Marks the migrations up to the target one (following the rules above) as
  550. applied, but without actually running the SQL to change your database schema.
  551. This is intended for advanced users to manipulate the
  552. current migration state directly if they're manually applying changes;
  553. be warned that using ``--fake`` runs the risk of putting the migration state
  554. table into a state where manual recovery will be needed to make migrations
  555. run correctly.
  556. .. django-admin-option:: --fake-initial
  557. Allows Django to skip an app's initial migration if all database tables with
  558. the names of all models created by all
  559. :class:`~django.db.migrations.operations.CreateModel` operations in that
  560. migration already exist. This option is intended for use when first running
  561. migrations against a database that preexisted the use of migrations. This
  562. option does not, however, check for matching database schema beyond matching
  563. table names and so is only safe to use if you are confident that your existing
  564. schema matches what is recorded in your initial migration.
  565. .. django-admin-option:: --plan
  566. .. versionadded:: 2.2
  567. Shows the migration operations that will be performed for the given ``migrate``
  568. command.
  569. .. django-admin-option:: --run-syncdb
  570. Allows creating tables for apps without migrations. While this isn't
  571. recommended, the migrations framework is sometimes too slow on large projects
  572. with hundreds of models.
  573. .. django-admin-option:: --noinput, --no-input
  574. Suppresses all user prompts. An example prompt is asking about removing stale
  575. content types.
  576. ``runserver``
  577. -------------
  578. .. django-admin:: runserver [addrport]
  579. Starts a lightweight development Web server on the local machine. By default,
  580. the server runs on port 8000 on the IP address ``127.0.0.1``. You can pass in an
  581. IP address and port number explicitly.
  582. If you run this script as a user with normal privileges (recommended), you
  583. might not have access to start a port on a low port number. Low port numbers
  584. are reserved for the superuser (root).
  585. This server uses the WSGI application object specified by the
  586. :setting:`WSGI_APPLICATION` setting.
  587. DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through
  588. security audits or performance tests. (And that's how it's gonna stay. We're in
  589. the business of making Web frameworks, not Web servers, so improving this
  590. server to be able to handle a production environment is outside the scope of
  591. Django.)
  592. The development server automatically reloads Python code for each request, as
  593. needed. You don't need to restart the server for code changes to take effect.
  594. However, some actions like adding files don't trigger a restart, so you'll
  595. have to restart the server in these cases.
  596. If you're using Linux or MacOS and install both `pywatchman`_ and the
  597. `Watchman`_ service, kernel signals will be used to autoreload the server
  598. (rather than polling file modification timestamps each second). This offers
  599. better performance on large projects, reduced response time after code changes,
  600. more robust change detection, and a reduction in power usage. Django supports
  601. ``pywatchman`` 1.2.0 and higher.
  602. .. admonition:: Large directories with many files may cause performance issues
  603. When using Watchman with a project that includes large non-Python
  604. directories like ``node_modules``, it's advisable to ignore this directory
  605. for optimal performance. See the `watchman documentation`_ for information
  606. on how to do this.
  607. .. admonition:: Watchman timeout
  608. The default timeout of ``Watchman`` client is 5 seconds. You can change it
  609. by setting the ``DJANGO_WATCHMAN_TIMEOUT`` environment variable.
  610. .. _Watchman: https://facebook.github.io/watchman/
  611. .. _pywatchman: https://pypi.org/project/pywatchman/
  612. .. _watchman documentation: https://facebook.github.io/watchman/docs/config.html#ignore_dirs
  613. .. versionchanged:: 2.2
  614. Watchman support replaced support for `pyinotify`.
  615. When you start the server, and each time you change Python code while the
  616. server is running, the system check framework will check your entire Django
  617. project for some common errors (see the :djadmin:`check` command). If any
  618. errors are found, they will be printed to standard output.
  619. You can run as many concurrent servers as you want, as long as they're on
  620. separate ports. Just execute ``django-admin runserver`` more than once.
  621. Note that the default IP address, ``127.0.0.1``, is not accessible from other
  622. machines on your network. To make your development server viewable to other
  623. machines on the network, use its own IP address (e.g. ``192.168.2.1``) or
  624. ``0.0.0.0`` or ``::`` (with IPv6 enabled).
  625. You can provide an IPv6 address surrounded by brackets
  626. (e.g. ``[200a::1]:8000``). This will automatically enable IPv6 support.
  627. A hostname containing ASCII-only characters can also be used.
  628. If the :doc:`staticfiles</ref/contrib/staticfiles>` contrib app is enabled
  629. (default in new projects) the :djadmin:`runserver` command will be overridden
  630. with its own :ref:`runserver<staticfiles-runserver>` command.
  631. Logging of each request and response of the server is sent to the
  632. :ref:`django-server-logger` logger.
  633. .. django-admin-option:: --noreload
  634. Disables the auto-reloader. This means any Python code changes you make while
  635. the server is running will *not* take effect if the particular Python modules
  636. have already been loaded into memory.
  637. .. django-admin-option:: --nothreading
  638. Disables use of threading in the development server. The server is
  639. multithreaded by default.
  640. .. django-admin-option:: --ipv6, -6
  641. Uses IPv6 for the development server. This changes the default IP address from
  642. ``127.0.0.1`` to ``::1``.
  643. Examples of using different ports and addresses
  644. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  645. Port 8000 on IP address ``127.0.0.1``::
  646. django-admin runserver
  647. Port 8000 on IP address ``1.2.3.4``::
  648. django-admin runserver 1.2.3.4:8000
  649. Port 7000 on IP address ``127.0.0.1``::
  650. django-admin runserver 7000
  651. Port 7000 on IP address ``1.2.3.4``::
  652. django-admin runserver 1.2.3.4:7000
  653. Port 8000 on IPv6 address ``::1``::
  654. django-admin runserver -6
  655. Port 7000 on IPv6 address ``::1``::
  656. django-admin runserver -6 7000
  657. Port 7000 on IPv6 address ``2001:0db8:1234:5678::9``::
  658. django-admin runserver [2001:0db8:1234:5678::9]:7000
  659. Port 8000 on IPv4 address of host ``localhost``::
  660. django-admin runserver localhost:8000
  661. Port 8000 on IPv6 address of host ``localhost``::
  662. django-admin runserver -6 localhost:8000
  663. Serving static files with the development server
  664. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  665. By default, the development server doesn't serve any static files for your site
  666. (such as CSS files, images, things under :setting:`MEDIA_URL` and so forth). If
  667. you want to configure Django to serve static media, read
  668. :doc:`/howto/static-files/index`.
  669. ``sendtestemail``
  670. -----------------
  671. .. django-admin:: sendtestemail [email [email ...]]
  672. Sends a test email (to confirm email sending through Django is working) to the
  673. recipient(s) specified. For example::
  674. django-admin sendtestemail foo@example.com bar@example.com
  675. There are a couple of options, and you may use any combination of them
  676. together:
  677. .. django-admin-option:: --managers
  678. Mails the email addresses specified in :setting:`MANAGERS` using
  679. :meth:`~django.core.mail.mail_managers()`.
  680. .. django-admin-option:: --admins
  681. Mails the email addresses specified in :setting:`ADMINS` using
  682. :meth:`~django.core.mail.mail_admins()`.
  683. ``shell``
  684. ---------
  685. .. django-admin:: shell
  686. Starts the Python interactive interpreter.
  687. .. django-admin-option:: --interface {ipython,bpython,python}, -i {ipython,bpython,python}
  688. Specifies the shell to use. By default, Django will use IPython_ or bpython_ if
  689. either is installed. If both are installed, specify which one you want like so:
  690. IPython::
  691. django-admin shell -i ipython
  692. bpython::
  693. django-admin shell -i bpython
  694. If you have a "rich" shell installed but want to force use of the "plain"
  695. Python interpreter, use ``python`` as the interface name, like so::
  696. django-admin shell -i python
  697. .. _IPython: https://ipython.org/
  698. .. _bpython: https://bpython-interpreter.org/
  699. .. django-admin-option:: --nostartup
  700. Disables reading the startup script for the "plain" Python interpreter. By
  701. default, the script pointed to by the :envvar:`PYTHONSTARTUP` environment
  702. variable or the ``~/.pythonrc.py`` script is read.
  703. .. django-admin-option:: --command COMMAND, -c COMMAND
  704. Lets you pass a command as a string to execute it as Django, like so::
  705. django-admin shell --command="import django; print(django.__version__)"
  706. You can also pass code in on standard input to execute it. For example:
  707. .. code-block:: console
  708. $ django-admin shell <<EOF
  709. > import django
  710. > print(django.__version__)
  711. > EOF
  712. On Windows, the REPL is output due to implementation limits of
  713. :func:`select.select` on that platform.
  714. ``showmigrations``
  715. ------------------
  716. .. django-admin:: showmigrations [app_label [app_label ...]]
  717. Shows all migrations in a project. You can choose from one of two formats:
  718. .. django-admin-option:: --list, -l
  719. Lists all of the apps Django knows about, the migrations available for each
  720. app, and whether or not each migration is applied (marked by an ``[X]`` next to
  721. the migration name). For a ``--verbosity`` of 2 and above, the applied
  722. datetimes are also shown.
  723. Apps without migrations are also listed, but have ``(no migrations)`` printed
  724. under them.
  725. This is the default output format.
  726. .. versionchanged:: 3.0
  727. Output of the applied datetimes at verbosity 2 and above was added.
  728. .. django-admin-option:: --plan, -p
  729. Shows the migration plan Django will follow to apply migrations. Like
  730. ``--list``, applied migrations are marked by an ``[X]``. For a ``--verbosity``
  731. of 2 and above, all dependencies of a migration will also be shown.
  732. ``app_label``\s arguments limit the output, however, dependencies of provided
  733. apps may also be included.
  734. .. django-admin-option:: --database DATABASE
  735. Specifies the database to examine. Defaults to ``default``.
  736. ``sqlflush``
  737. ------------
  738. .. django-admin:: sqlflush
  739. Prints the SQL statements that would be executed for the :djadmin:`flush`
  740. command.
  741. .. django-admin-option:: --database DATABASE
  742. Specifies the database for which to print the SQL. Defaults to ``default``.
  743. ``sqlmigrate``
  744. --------------
  745. .. django-admin:: sqlmigrate app_label migration_name
  746. Prints the SQL for the named migration. This requires an active database
  747. connection, which it will use to resolve constraint names; this means you must
  748. generate the SQL against a copy of the database you wish to later apply it on.
  749. Note that ``sqlmigrate`` doesn't colorize its output.
  750. .. django-admin-option:: --backwards
  751. Generates the SQL for unapplying the migration. By default, the SQL created is
  752. for running the migration in the forwards direction.
  753. .. django-admin-option:: --database DATABASE
  754. Specifies the database for which to generate the SQL. Defaults to ``default``.
  755. ``sqlsequencereset``
  756. --------------------
  757. .. django-admin:: sqlsequencereset app_label [app_label ...]
  758. Prints the SQL statements for resetting sequences for the given app name(s).
  759. Sequences are indexes used by some database engines to track the next available
  760. number for automatically incremented fields.
  761. Use this command to generate SQL which will fix cases where a sequence is out
  762. of sync with its automatically incremented field data.
  763. .. django-admin-option:: --database DATABASE
  764. Specifies the database for which to print the SQL. Defaults to ``default``.
  765. ``squashmigrations``
  766. --------------------
  767. .. django-admin:: squashmigrations app_label [start_migration_name] migration_name
  768. Squashes the migrations for ``app_label`` up to and including ``migration_name``
  769. down into fewer migrations, if possible. The resulting squashed migrations
  770. can live alongside the unsquashed ones safely. For more information,
  771. please read :ref:`migration-squashing`.
  772. When ``start_migration_name`` is given, Django will only include migrations
  773. starting from and including this migration. This helps to mitigate the
  774. squashing limitation of :class:`~django.db.migrations.operations.RunPython` and
  775. :class:`django.db.migrations.operations.RunSQL` migration operations.
  776. .. django-admin-option:: --no-optimize
  777. Disables the optimizer when generating a squashed migration. By default, Django
  778. will try to optimize the operations in your migrations to reduce the size of
  779. the resulting file. Use this option if this process is failing or creating
  780. incorrect migrations, though please also file a Django bug report about the
  781. behavior, as optimization is meant to be safe.
  782. .. django-admin-option:: --noinput, --no-input
  783. Suppresses all user prompts.
  784. .. django-admin-option:: --squashed-name SQUASHED_NAME
  785. Sets the name of the squashed migration. When omitted, the name is based on the
  786. first and last migration, with ``_squashed_`` in between.
  787. .. django-admin-option:: --no-header
  788. .. versionadded:: 2.2
  789. Generate squashed migration file without Django version and timestamp header.
  790. ``startapp``
  791. ------------
  792. .. django-admin:: startapp name [directory]
  793. Creates a Django app directory structure for the given app name in the current
  794. directory or the given destination.
  795. By default, :source:`the new directory <django/conf/app_template>` contains a
  796. ``models.py`` file and other app template files. If only the app name is given,
  797. the app directory will be created in the current working directory.
  798. If the optional destination is provided, Django will use that existing
  799. directory rather than creating a new one. You can use '.' to denote the current
  800. working directory.
  801. For example::
  802. django-admin startapp myapp /Users/jezdez/Code/myapp
  803. .. _custom-app-and-project-templates:
  804. .. django-admin-option:: --template TEMPLATE
  805. Provides the path to a directory with a custom app template file or a path to a
  806. compressed file (``.tar.gz``, ``.tar.bz2``, ``.tgz``, ``.tbz``, ``.zip``)
  807. containing the app template files.
  808. For example, this would look for an app template in the given directory when
  809. creating the ``myapp`` app::
  810. django-admin startapp --template=/Users/jezdez/Code/my_app_template myapp
  811. Django will also accept URLs (``http``, ``https``, ``ftp``) to compressed
  812. archives with the app template files, downloading and extracting them on the
  813. fly.
  814. For example, taking advantage of GitHub's feature to expose repositories as
  815. zip files, you can use a URL like::
  816. django-admin startapp --template=https://github.com/githubuser/django-app-template/archive/master.zip myapp
  817. .. django-admin-option:: --extension EXTENSIONS, -e EXTENSIONS
  818. Specifies which file extensions in the app template should be rendered with the
  819. template engine. Defaults to ``py``.
  820. .. django-admin-option:: --name FILES, -n FILES
  821. Specifies which files in the app template (in addition to those matching
  822. ``--extension``) should be rendered with the template engine. Defaults to an
  823. empty list.
  824. The :class:`template context <django.template.Context>` used for all matching
  825. files is:
  826. - Any option passed to the ``startapp`` command (among the command's supported
  827. options)
  828. - ``app_name`` -- the app name as passed to the command
  829. - ``app_directory`` -- the full path of the newly created app
  830. - ``camel_case_app_name`` -- the app name in camel case format
  831. - ``docs_version`` -- the version of the documentation: ``'dev'`` or ``'1.x'``
  832. - ``django_version`` -- the version of Django, e.g. ``'2.0.3'``
  833. .. _render_warning:
  834. .. warning::
  835. When the app template files are rendered with the Django template
  836. engine (by default all ``*.py`` files), Django will also replace all
  837. stray template variables contained. For example, if one of the Python files
  838. contains a docstring explaining a particular feature related
  839. to template rendering, it might result in an incorrect example.
  840. To work around this problem, you can use the :ttag:`templatetag`
  841. template tag to "escape" the various parts of the template syntax.
  842. In addition, to allow Python template files that contain Django template
  843. language syntax while also preventing packaging systems from trying to
  844. byte-compile invalid ``*.py`` files, template files ending with ``.py-tpl``
  845. will be renamed to ``.py``.
  846. ``startproject``
  847. ----------------
  848. .. django-admin:: startproject name [directory]
  849. Creates a Django project directory structure for the given project name in
  850. the current directory or the given destination.
  851. By default, :source:`the new directory <django/conf/project_template>` contains
  852. ``manage.py`` and a project package (containing a ``settings.py`` and other
  853. files).
  854. If only the project name is given, both the project directory and project
  855. package will be named ``<projectname>`` and the project directory
  856. will be created in the current working directory.
  857. If the optional destination is provided, Django will use that existing
  858. directory as the project directory, and create ``manage.py`` and the project
  859. package within it. Use '.' to denote the current working directory.
  860. For example::
  861. django-admin startproject myproject /Users/jezdez/Code/myproject_repo
  862. .. django-admin-option:: --template TEMPLATE
  863. Specifies a directory, file path, or URL of a custom project template. See the
  864. :option:`startapp --template` documentation for examples and usage.
  865. .. django-admin-option:: --extension EXTENSIONS, -e EXTENSIONS
  866. Specifies which file extensions in the project template should be rendered with
  867. the template engine. Defaults to ``py``.
  868. .. django-admin-option:: --name FILES, -n FILES
  869. Specifies which files in the project template (in addition to those matching
  870. ``--extension``) should be rendered with the template engine. Defaults to an
  871. empty list.
  872. The :class:`template context <django.template.Context>` used is:
  873. - Any option passed to the ``startproject`` command (among the command's
  874. supported options)
  875. - ``project_name`` -- the project name as passed to the command
  876. - ``project_directory`` -- the full path of the newly created project
  877. - ``secret_key`` -- a random key for the :setting:`SECRET_KEY` setting
  878. - ``docs_version`` -- the version of the documentation: ``'dev'`` or ``'1.x'``
  879. - ``django_version`` -- the version of Django, e.g. ``'2.0.3'``
  880. Please also see the :ref:`rendering warning <render_warning>` as mentioned
  881. for :djadmin:`startapp`.
  882. ``test``
  883. --------
  884. .. django-admin:: test [test_label [test_label ...]]
  885. Runs tests for all installed apps. See :doc:`/topics/testing/index` for more
  886. information.
  887. .. django-admin-option:: --failfast
  888. Stops running tests and reports the failure immediately after a test fails.
  889. .. django-admin-option:: --testrunner TESTRUNNER
  890. Controls the test runner class that is used to execute tests. This value
  891. overrides the value provided by the :setting:`TEST_RUNNER` setting.
  892. .. django-admin-option:: --noinput, --no-input
  893. Suppresses all user prompts. A typical prompt is a warning about deleting an
  894. existing test database.
  895. Test runner options
  896. ~~~~~~~~~~~~~~~~~~~
  897. The ``test`` command receives options on behalf of the specified
  898. :option:`--testrunner`. These are the options of the default test runner:
  899. :class:`~django.test.runner.DiscoverRunner`.
  900. .. django-admin-option:: --keepdb
  901. Preserves the test database between test runs. This has the advantage of
  902. skipping both the create and destroy actions which can greatly decrease the
  903. time to run tests, especially those in a large test suite. If the test database
  904. does not exist, it will be created on the first run and then preserved for each
  905. subsequent run. Any unapplied migrations will also be applied to the test
  906. database before running the test suite.
  907. .. django-admin-option:: --reverse, -r
  908. Sorts test cases in the opposite execution order. This may help in debugging
  909. the side effects of tests that aren't properly isolated. :ref:`Grouping by test
  910. class <order-of-tests>` is preserved when using this option.
  911. .. django-admin-option:: --debug-mode
  912. Sets the :setting:`DEBUG` setting to ``True`` prior to running tests. This may
  913. help troubleshoot test failures.
  914. .. django-admin-option:: --debug-sql, -d
  915. Enables :ref:`SQL logging <django-db-logger>` for failing tests. If
  916. ``--verbosity`` is ``2``, then queries in passing tests are also output.
  917. .. django-admin-option:: --parallel [N]
  918. Runs tests in separate parallel processes. Since modern processors have
  919. multiple cores, this allows running tests significantly faster.
  920. By default ``--parallel`` runs one process per core according to
  921. :func:`multiprocessing.cpu_count()`. You can adjust the number of processes
  922. either by providing it as the option's value, e.g. ``--parallel=4``, or by
  923. setting the ``DJANGO_TEST_PROCESSES`` environment variable.
  924. Django distributes test cases — :class:`unittest.TestCase` subclasses — to
  925. subprocesses. If there are fewer test cases than configured processes, Django
  926. will reduce the number of processes accordingly.
  927. Each process gets its own database. You must ensure that different test cases
  928. don't access the same resources. For instance, test cases that touch the
  929. filesystem should create a temporary directory for their own use.
  930. This option requires the third-party ``tblib`` package to display tracebacks
  931. correctly:
  932. .. code-block:: console
  933. $ python -m pip install tblib
  934. This feature isn't available on Windows. It doesn't work with the Oracle
  935. database backend either.
  936. If you want to use :mod:`pdb` while debugging tests, you must disable parallel
  937. execution (``--parallel=1``). You'll see something like ``bdb.BdbQuit`` if you
  938. don't.
  939. .. warning::
  940. When test parallelization is enabled and a test fails, Django may be
  941. unable to display the exception traceback. This can make debugging
  942. difficult. If you encounter this problem, run the affected test without
  943. parallelization to see the traceback of the failure.
  944. This is a known limitation. It arises from the need to serialize objects
  945. in order to exchange them between processes. See
  946. :ref:`python:pickle-picklable` for details.
  947. .. option:: --tag TAGS
  948. Runs only tests :ref:`marked with the specified tags <topics-tagging-tests>`.
  949. May be specified multiple times and combined with :option:`test --exclude-tag`.
  950. .. option:: --exclude-tag EXCLUDE_TAGS
  951. Excludes tests :ref:`marked with the specified tags <topics-tagging-tests>`.
  952. May be specified multiple times and combined with :option:`test --tag`.
  953. .. django-admin-option:: -k TEST_NAME_PATTERNS
  954. .. versionadded:: 3.0
  955. Runs test methods and classes matching test name patterns, in the same way as
  956. :option:`unittest's -k option<unittest.-k>`. Can be specified multiple times.
  957. .. admonition:: Python 3.7 and later
  958. This feature is only available for Python 3.7 and later.
  959. ``testserver``
  960. --------------
  961. .. django-admin:: testserver [fixture [fixture ...]]
  962. Runs a Django development server (as in :djadmin:`runserver`) using data from
  963. the given fixture(s).
  964. For example, this command::
  965. django-admin testserver mydata.json
  966. ...would perform the following steps:
  967. #. Create a test database, as described in :ref:`the-test-database`.
  968. #. Populate the test database with fixture data from the given fixtures.
  969. (For more on fixtures, see the documentation for :djadmin:`loaddata` above.)
  970. #. Runs the Django development server (as in :djadmin:`runserver`), pointed at
  971. this newly created test database instead of your production database.
  972. This is useful in a number of ways:
  973. * When you're writing :doc:`unit tests </topics/testing/overview>` of how your views
  974. act with certain fixture data, you can use ``testserver`` to interact with
  975. the views in a Web browser, manually.
  976. * Let's say you're developing your Django application and have a "pristine"
  977. copy of a database that you'd like to interact with. You can dump your
  978. database to a fixture (using the :djadmin:`dumpdata` command, explained
  979. above), then use ``testserver`` to run your Web application with that data.
  980. With this arrangement, you have the flexibility of messing up your data
  981. in any way, knowing that whatever data changes you're making are only
  982. being made to a test database.
  983. Note that this server does *not* automatically detect changes to your Python
  984. source code (as :djadmin:`runserver` does). It does, however, detect changes to
  985. templates.
  986. .. django-admin-option:: --addrport ADDRPORT
  987. Specifies a different port, or IP address and port, from the default of
  988. ``127.0.0.1:8000``. This value follows exactly the same format and serves
  989. exactly the same function as the argument to the :djadmin:`runserver` command.
  990. Examples:
  991. To run the test server on port 7000 with ``fixture1`` and ``fixture2``::
  992. django-admin testserver --addrport 7000 fixture1 fixture2
  993. django-admin testserver fixture1 fixture2 --addrport 7000
  994. (The above statements are equivalent. We include both of them to demonstrate
  995. that it doesn't matter whether the options come before or after the fixture
  996. arguments.)
  997. To run on 1.2.3.4:7000 with a ``test`` fixture::
  998. django-admin testserver --addrport 1.2.3.4:7000 test
  999. .. django-admin-option:: --noinput, --no-input
  1000. Suppresses all user prompts. A typical prompt is a warning about deleting an
  1001. existing test database.
  1002. Commands provided by applications
  1003. =================================
  1004. Some commands are only available when the ``django.contrib`` application that
  1005. :doc:`implements </howto/custom-management-commands>` them has been
  1006. :setting:`enabled <INSTALLED_APPS>`. This section describes them grouped by
  1007. their application.
  1008. ``django.contrib.auth``
  1009. -----------------------
  1010. ``changepassword``
  1011. ~~~~~~~~~~~~~~~~~~
  1012. .. django-admin:: changepassword [<username>]
  1013. This command is only available if Django's :doc:`authentication system
  1014. </topics/auth/index>` (``django.contrib.auth``) is installed.
  1015. Allows changing a user's password. It prompts you to enter a new password twice
  1016. for the given user. If the entries are identical, this immediately becomes the
  1017. new password. If you do not supply a user, the command will attempt to change
  1018. the password whose username matches the current user.
  1019. .. django-admin-option:: --database DATABASE
  1020. Specifies the database to query for the user. Defaults to ``default``.
  1021. Example usage::
  1022. django-admin changepassword ringo
  1023. ``createsuperuser``
  1024. ~~~~~~~~~~~~~~~~~~~
  1025. .. django-admin:: createsuperuser
  1026. This command is only available if Django's :doc:`authentication system
  1027. </topics/auth/index>` (``django.contrib.auth``) is installed.
  1028. Creates a superuser account (a user who has all permissions). This is
  1029. useful if you need to create an initial superuser account or if you need to
  1030. programmatically generate superuser accounts for your site(s).
  1031. When run interactively, this command will prompt for a password for
  1032. the new superuser account. When run non-interactively, you can provide
  1033. a password by setting the ``DJANGO_SUPERUSER_PASSWORD`` environment variable.
  1034. Otherwise, no password will be set, and the superuser account will not be able
  1035. to log in until a password has been manually set for it.
  1036. In non-interactive mode, the
  1037. :attr:`~django.contrib.auth.models.CustomUser.USERNAME_FIELD` and required
  1038. fields (listed in
  1039. :attr:`~django.contrib.auth.models.CustomUser.REQUIRED_FIELDS`) fall back to
  1040. ``DJANGO_SUPERUSER_<uppercase_field_name>`` environment variables, unless they
  1041. are overridden by a command line argument. For example, to provide an ``email``
  1042. field, you can use ``DJANGO_SUPERUSER_EMAIL`` environment variable.
  1043. .. versionchanged:: 3.0
  1044. Support for using ``DJANGO_SUPERUSER_PASSWORD`` and
  1045. ``DJANGO_SUPERUSER_<uppercase_field_name>`` environment variables was added.
  1046. .. django-admin-option:: --username USERNAME
  1047. .. django-admin-option:: --email EMAIL
  1048. The username and email address for the new account can be supplied by
  1049. using the ``--username`` and ``--email`` arguments on the command
  1050. line. If either of those is not supplied, ``createsuperuser`` will prompt for
  1051. it when running interactively.
  1052. .. django-admin-option:: --database DATABASE
  1053. Specifies the database into which the superuser object will be saved.
  1054. You can subclass the management command and override ``get_input_data()`` if you
  1055. want to customize data input and validation. Consult the source code for
  1056. details on the existing implementation and the method's parameters. For example,
  1057. it could be useful if you have a ``ForeignKey`` in
  1058. :attr:`~django.contrib.auth.models.CustomUser.REQUIRED_FIELDS` and want to
  1059. allow creating an instance instead of entering the primary key of an existing
  1060. instance.
  1061. ``django.contrib.contenttypes``
  1062. -------------------------------
  1063. ``remove_stale_contenttypes``
  1064. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1065. .. django-admin:: remove_stale_contenttypes
  1066. This command is only available if Django's :doc:`contenttypes app
  1067. </ref/contrib/contenttypes>` (:mod:`django.contrib.contenttypes`) is installed.
  1068. Deletes stale content types (from deleted models) in your database. Any objects
  1069. that depend on the deleted content types will also be deleted. A list of
  1070. deleted objects will be displayed before you confirm it's okay to proceed with
  1071. the deletion.
  1072. .. django-admin-option:: --database DATABASE
  1073. Specifies the database to use. Defaults to ``default``.
  1074. ``django.contrib.gis``
  1075. ----------------------
  1076. ``ogrinspect``
  1077. ~~~~~~~~~~~~~~
  1078. This command is only available if :doc:`GeoDjango </ref/contrib/gis/index>`
  1079. (``django.contrib.gis``) is installed.
  1080. Please refer to its :djadmin:`description <ogrinspect>` in the GeoDjango
  1081. documentation.
  1082. ``django.contrib.sessions``
  1083. ---------------------------
  1084. ``clearsessions``
  1085. ~~~~~~~~~~~~~~~~~
  1086. .. django-admin:: clearsessions
  1087. Can be run as a cron job or directly to clean out expired sessions.
  1088. ``django.contrib.sitemaps``
  1089. ---------------------------
  1090. ``ping_google``
  1091. ~~~~~~~~~~~~~~~
  1092. This command is only available if the :doc:`Sitemaps framework
  1093. </ref/contrib/sitemaps>` (``django.contrib.sitemaps``) is installed.
  1094. Please refer to its :djadmin:`description <ping_google>` in the Sitemaps
  1095. documentation.
  1096. ``django.contrib.staticfiles``
  1097. ------------------------------
  1098. ``collectstatic``
  1099. ~~~~~~~~~~~~~~~~~
  1100. This command is only available if the :doc:`static files application
  1101. </howto/static-files/index>` (``django.contrib.staticfiles``) is installed.
  1102. Please refer to its :djadmin:`description <collectstatic>` in the
  1103. :doc:`staticfiles </ref/contrib/staticfiles>` documentation.
  1104. ``findstatic``
  1105. ~~~~~~~~~~~~~~
  1106. This command is only available if the :doc:`static files application
  1107. </howto/static-files/index>` (``django.contrib.staticfiles``) is installed.
  1108. Please refer to its :djadmin:`description <findstatic>` in the :doc:`staticfiles
  1109. </ref/contrib/staticfiles>` documentation.
  1110. Default options
  1111. ===============
  1112. .. program:: None
  1113. Although some commands may allow their own custom options, every command
  1114. allows for the following options:
  1115. .. django-admin-option:: --pythonpath PYTHONPATH
  1116. Adds the given filesystem path to the Python `import search path`_. If this
  1117. isn't provided, ``django-admin`` will use the ``PYTHONPATH`` environment
  1118. variable.
  1119. This option is unnecessary in ``manage.py``, because it takes care of setting
  1120. the Python path for you.
  1121. Example usage::
  1122. django-admin migrate --pythonpath='/home/djangoprojects/myproject'
  1123. .. _import search path: https://www.diveinto.org/python3/your-first-python-program.html#importsearchpath
  1124. .. django-admin-option:: --settings SETTINGS
  1125. Specifies the settings module to use. The settings module should be in Python
  1126. package syntax, e.g. ``mysite.settings``. If this isn't provided,
  1127. ``django-admin`` will use the ``DJANGO_SETTINGS_MODULE`` environment variable.
  1128. This option is unnecessary in ``manage.py``, because it uses
  1129. ``settings.py`` from the current project by default.
  1130. Example usage::
  1131. django-admin migrate --settings=mysite.settings
  1132. .. django-admin-option:: --traceback
  1133. Displays a full stack trace when a :exc:`~django.core.management.CommandError`
  1134. is raised. By default, ``django-admin`` will show a simple error message when a
  1135. ``CommandError`` occurs and a full stack trace for any other exception.
  1136. Example usage::
  1137. django-admin migrate --traceback
  1138. .. django-admin-option:: --verbosity {0,1,2,3}, -v {0,1,2,3}
  1139. Specifies the amount of notification and debug information that a command
  1140. should print to the console.
  1141. * ``0`` means no output.
  1142. * ``1`` means normal output (default).
  1143. * ``2`` means verbose output.
  1144. * ``3`` means *very* verbose output.
  1145. Example usage::
  1146. django-admin migrate --verbosity 2
  1147. .. django-admin-option:: --no-color
  1148. Disables colorized command output. Some commands format their output to be
  1149. colorized. For example, errors will be printed to the console in red and SQL
  1150. statements will be syntax highlighted.
  1151. Example usage::
  1152. django-admin runserver --no-color
  1153. .. django-admin-option:: --force-color
  1154. .. versionadded:: 2.2
  1155. Forces colorization of the command output if it would otherwise be disabled
  1156. as discussed in :ref:`syntax-coloring`. For example, you may want to pipe
  1157. colored output to another command.
  1158. .. django-admin-option:: --skip-checks
  1159. .. versionadded:: 3.0
  1160. Skips running system checks prior to running the command. This option is only
  1161. available if the
  1162. :attr:`~django.core.management.BaseCommand.requires_system_checks` command
  1163. attribute is set to ``True``.
  1164. Example usage::
  1165. django-admin migrate --skip-checks
  1166. Extra niceties
  1167. ==============
  1168. .. _syntax-coloring:
  1169. Syntax coloring
  1170. ---------------
  1171. The ``django-admin`` / ``manage.py`` commands will use pretty
  1172. color-coded output if your terminal supports ANSI-colored output. It
  1173. won't use the color codes if you're piping the command's output to
  1174. another program unless the :option:`--force-color` option is used.
  1175. Under Windows, the native console doesn't support ANSI escape sequences so by
  1176. default there is no color output. But you can install the `ANSICON`_
  1177. third-party tool, the Django commands will detect its presence and will make
  1178. use of its services to color output just like on Unix-based platforms.
  1179. The colors used for syntax highlighting can be customized. Django
  1180. ships with three color palettes:
  1181. * ``dark``, suited to terminals that show white text on a black
  1182. background. This is the default palette.
  1183. * ``light``, suited to terminals that show black text on a white
  1184. background.
  1185. * ``nocolor``, which disables syntax highlighting.
  1186. You select a palette by setting a ``DJANGO_COLORS`` environment
  1187. variable to specify the palette you want to use. For example, to
  1188. specify the ``light`` palette under a Unix or OS/X BASH shell, you
  1189. would run the following at a command prompt::
  1190. export DJANGO_COLORS="light"
  1191. You can also customize the colors that are used. Django specifies a
  1192. number of roles in which color is used:
  1193. * ``error`` - A major error.
  1194. * ``notice`` - A minor error.
  1195. * ``success`` - A success.
  1196. * ``warning`` - A warning.
  1197. * ``sql_field`` - The name of a model field in SQL.
  1198. * ``sql_coltype`` - The type of a model field in SQL.
  1199. * ``sql_keyword`` - An SQL keyword.
  1200. * ``sql_table`` - The name of a model in SQL.
  1201. * ``http_info`` - A 1XX HTTP Informational server response.
  1202. * ``http_success`` - A 2XX HTTP Success server response.
  1203. * ``http_not_modified`` - A 304 HTTP Not Modified server response.
  1204. * ``http_redirect`` - A 3XX HTTP Redirect server response other than 304.
  1205. * ``http_not_found`` - A 404 HTTP Not Found server response.
  1206. * ``http_bad_request`` - A 4XX HTTP Bad Request server response other than 404.
  1207. * ``http_server_error`` - A 5XX HTTP Server Error response.
  1208. * ``migrate_heading`` - A heading in a migrations management command.
  1209. * ``migrate_label`` - A migration name.
  1210. Each of these roles can be assigned a specific foreground and
  1211. background color, from the following list:
  1212. * ``black``
  1213. * ``red``
  1214. * ``green``
  1215. * ``yellow``
  1216. * ``blue``
  1217. * ``magenta``
  1218. * ``cyan``
  1219. * ``white``
  1220. Each of these colors can then be modified by using the following
  1221. display options:
  1222. * ``bold``
  1223. * ``underscore``
  1224. * ``blink``
  1225. * ``reverse``
  1226. * ``conceal``
  1227. A color specification follows one of the following patterns:
  1228. * ``role=fg``
  1229. * ``role=fg/bg``
  1230. * ``role=fg,option,option``
  1231. * ``role=fg/bg,option,option``
  1232. where ``role`` is the name of a valid color role, ``fg`` is the
  1233. foreground color, ``bg`` is the background color and each ``option``
  1234. is one of the color modifying options. Multiple color specifications
  1235. are then separated by a semicolon. For example::
  1236. export DJANGO_COLORS="error=yellow/blue,blink;notice=magenta"
  1237. would specify that errors be displayed using blinking yellow on blue,
  1238. and notices displayed using magenta. All other color roles would be
  1239. left uncolored.
  1240. Colors can also be specified by extending a base palette. If you put
  1241. a palette name in a color specification, all the colors implied by that
  1242. palette will be loaded. So::
  1243. export DJANGO_COLORS="light;error=yellow/blue,blink;notice=magenta"
  1244. would specify the use of all the colors in the light color palette,
  1245. *except* for the colors for errors and notices which would be
  1246. overridden as specified.
  1247. .. _ANSICON: http://adoxa.altervista.org/ansicon/
  1248. Bash completion
  1249. ---------------
  1250. If you use the Bash shell, consider installing the Django bash completion
  1251. script, which lives in ``extras/django_bash_completion`` in the Django source
  1252. distribution. It enables tab-completion of ``django-admin`` and
  1253. ``manage.py`` commands, so you can, for instance...
  1254. * Type ``django-admin``.
  1255. * Press [TAB] to see all available options.
  1256. * Type ``sql``, then [TAB], to see all available options whose names start
  1257. with ``sql``.
  1258. See :doc:`/howto/custom-management-commands` for how to add customized actions.
  1259. ==========================================
  1260. Running management commands from your code
  1261. ==========================================
  1262. .. function:: django.core.management.call_command(name, *args, **options)
  1263. To call a management command from code use ``call_command``.
  1264. ``name``
  1265. the name of the command to call or a command object. Passing the name is
  1266. preferred unless the object is required for testing.
  1267. ``*args``
  1268. a list of arguments accepted by the command. Arguments are passed to the
  1269. argument parser, so you can use the same style as you would on the command
  1270. line. For example, ``call_command('flush', '--verbosity=0')``.
  1271. ``**options``
  1272. named options accepted on the command-line. Options are passed to the command
  1273. without triggering the argument parser, which means you'll need to pass the
  1274. correct type. For example, ``call_command('flush', verbosity=0)`` (zero must
  1275. be an integer rather than a string).
  1276. Examples::
  1277. from django.core import management
  1278. from django.core.management.commands import loaddata
  1279. management.call_command('flush', verbosity=0, interactive=False)
  1280. management.call_command('loaddata', 'test_data', verbosity=0)
  1281. management.call_command(loaddata.Command(), 'test_data', verbosity=0)
  1282. Note that command options that take no arguments are passed as keywords
  1283. with ``True`` or ``False``, as you can see with the ``interactive`` option above.
  1284. Named arguments can be passed by using either one of the following syntaxes::
  1285. # Similar to the command line
  1286. management.call_command('dumpdata', '--natural-foreign')
  1287. # Named argument similar to the command line minus the initial dashes and
  1288. # with internal dashes replaced by underscores
  1289. management.call_command('dumpdata', natural_foreign=True)
  1290. # `use_natural_foreign_keys` is the option destination variable
  1291. management.call_command('dumpdata', use_natural_foreign_keys=True)
  1292. Some command options have different names when using ``call_command()`` instead
  1293. of ``django-admin`` or ``manage.py``. For example, ``django-admin
  1294. createsuperuser --no-input`` translates to ``call_command('createsuperuser',
  1295. interactive=False)``. To find what keyword argument name to use for
  1296. ``call_command()``, check the command's source code for the ``dest`` argument
  1297. passed to ``parser.add_argument()``.
  1298. Command options which take multiple options are passed a list::
  1299. management.call_command('dumpdata', exclude=['contenttypes', 'auth'])
  1300. The return value of the ``call_command()`` function is the same as the return
  1301. value of the ``handle()`` method of the command.
  1302. Output redirection
  1303. ==================
  1304. Note that you can redirect standard output and error streams as all commands
  1305. support the ``stdout`` and ``stderr`` options. For example, you could write::
  1306. with open('/path/to/command_output', 'w') as f:
  1307. management.call_command('dumpdata', stdout=f)