django-admin.txt 50 KB

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