django-admin.txt 43 KB

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