django-admin.txt 48 KB

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