django-admin.txt 61 KB

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