django-admin.txt 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. .. _ref-django-admin:
  2. =============================
  3. django-admin.py and manage.py
  4. =============================
  5. ``django-admin.py`` is Django's command-line utility for administrative tasks.
  6. This document outlines all it can do.
  7. In addition, ``manage.py`` is automatically created in each Django project.
  8. ``manage.py`` is a thin wrapper around ``django-admin.py`` that takes care of
  9. two things for you before delegating to ``django-admin.py``:
  10. * It puts your project's package on ``sys.path``.
  11. * It sets the :envvar:`DJANGO_SETTINGS_MODULE` environment variable so that
  12. it points to your project's ``settings.py`` file.
  13. The ``django-admin.py`` script should be on your system path if you installed
  14. Django via its ``setup.py`` utility. If it's not on your path, you can find it
  15. in ``site-packages/django/bin`` within your Python installation. Consider
  16. symlinking it from some place on your path, such as ``/usr/local/bin``.
  17. For Windows users, who do not have symlinking functionality available, you can
  18. copy ``django-admin.py`` to a location on your existing path or edit the
  19. ``PATH`` settings (under ``Settings - Control Panel - System - Advanced -
  20. Environment...``) to point to its installed location.
  21. Generally, when working on a single Django project, it's easier to use
  22. ``manage.py``. Use ``django-admin.py`` with ``DJANGO_SETTINGS_MODULE``, or the
  23. ``--settings`` command line option, if you need to switch between multiple
  24. Django settings files.
  25. The command-line examples throughout this document use ``django-admin.py`` to
  26. be consistent, but any example can use ``manage.py`` just as well.
  27. Usage
  28. =====
  29. .. code-block:: bash
  30. django-admin.py <subcommand> [options]
  31. manage.py <subcommand> [options]
  32. ``subcommand`` should be one of the subcommands listed in this document.
  33. ``options``, which is optional, should be zero or more of the options available
  34. for the given subcommand.
  35. Getting runtime help
  36. --------------------
  37. .. django-admin-option:: --help
  38. In Django 0.96, run ``django-admin.py --help`` to display a help message that
  39. includes a terse list of all available subcommands and options.
  40. In the Django development version, run ``django-admin.py help`` to display a
  41. list of all available subcommands. Run ``django-admin.py help <subcommand>``
  42. to display a description of the given subcommand and a list of its available
  43. options.
  44. App names
  45. ---------
  46. Many subcommands take a list of "app names." An "app name" is the basename of
  47. the package containing your models. For example, if your ``INSTALLED_APPS``
  48. contains the string ``'mysite.blog'``, the app name is ``blog``.
  49. Determining the version
  50. -----------------------
  51. .. django-admin-option:: --version
  52. Run ``django-admin.py --version`` to display the current Django version.
  53. Examples of output::
  54. 0.95
  55. 0.96
  56. 0.97-pre-SVN-6069
  57. Displaying debug output
  58. -----------------------
  59. .. django-admin-option:: --verbosity <amount>
  60. Use ``--verbosity`` to specify the amount of notification and debug information
  61. that ``django-admin.py`` should print to the console.
  62. * ``0`` means no output.
  63. * ``1`` means normal output (default).
  64. * ``2`` means verbose output.
  65. Available subcommands
  66. =====================
  67. cleanup
  68. -------
  69. **New in Django development version**
  70. Can be run as a cronjob or directly to clean out old data from the database
  71. (only expired sessions at the moment).
  72. compilemessages
  73. ---------------
  74. **New in Django development version**
  75. Compiles .po files created with ``makemessages`` to .mo files for use with
  76. the builtin gettext support. See :ref:`topics-i18n`.
  77. --locale
  78. ~~~~~~~~
  79. Use the ``--locale`` or ``-l`` option to specify the locale to process.
  80. If not provided all locales are processed.
  81. Example usage::
  82. django-admin.py compilemessages --locale=br_PT
  83. createcachetable
  84. ----------------
  85. .. django-admin:: createcachetable <tablename>
  86. Creates a cache table named ``tablename`` for use with the database cache
  87. backend. See :ref:`topics-cache` for more information.
  88. createsuperuser
  89. ---------------
  90. .. django-admin:: createsuperuser
  91. **New in Django development version**
  92. Creates a superuser account (a user who has all permissions). This is
  93. useful if you need to create an initial superuser account but did not
  94. do so during ``syncdb``, or if you need to programmatically generate
  95. superuser accounts for your site(s).
  96. When run interactively, this command will prompt for a password for
  97. the new superuser account. When run non-interactively, no password
  98. will be set, and the superuser account will not be able to log in until
  99. a password has been manually set for it.
  100. .. django-admin-option:: --username
  101. .. django-admin-option:: --email
  102. The username and e-mail address for the new account can be supplied by
  103. using the ``--username`` and ``--email`` arguments on the command
  104. line. If either of those is not supplied, ``createsuperuser`` will prompt for
  105. it when running interactively.
  106. This command is only available if Django's :ref:`authentication system
  107. <topics-auth>` (``django.contrib.auth``) is installed.
  108. dbshell
  109. -------
  110. .. django-admin:: dbshell
  111. Runs the command-line client for the database engine specified in your
  112. ``DATABASE_ENGINE`` setting, with the connection parameters specified in your
  113. ``DATABASE_USER``, ``DATABASE_PASSWORD``, etc., settings.
  114. * For PostgreSQL, this runs the ``psql`` command-line client.
  115. * For MySQL, this runs the ``mysql`` command-line client.
  116. * For SQLite, this runs the ``sqlite3`` command-line client.
  117. This command assumes the programs are on your ``PATH`` so that a simple call to
  118. the program name (``psql``, ``mysql``, ``sqlite3``) will find the program in
  119. the right place. There's no way to specify the location of the program
  120. manually.
  121. diffsettings
  122. ------------
  123. .. django-admin:: diffsettings
  124. Displays differences between the current settings file and Django's default
  125. settings.
  126. Settings that don't appear in the defaults are followed by ``"###"``. For
  127. example, the default settings don't define ``ROOT_URLCONF``, so
  128. ``ROOT_URLCONF`` is followed by ``"###"`` in the output of ``diffsettings``.
  129. Note that Django's default settings live in ``django/conf/global_settings.py``,
  130. if you're ever curious to see the full list of defaults.
  131. dumpdata
  132. --------
  133. .. django-admin:: dumpdata <appname appname ...>
  134. Outputs to standard output all data in the database associated with the named
  135. application(s).
  136. If no application name is provided, all installed applications will be dumped.
  137. The output of ``dumpdata`` can be used as input for ``loaddata``.
  138. Note that ``dumpdata`` uses the default manager on the model for selecting the
  139. records to dump. If you're using a :ref:`custom manager <custom-managers>` as
  140. the default manager and it filters some of the available records, not all of the
  141. objects will be dumped.
  142. .. django-admin-option:: --exclude
  143. **New in Django development version**
  144. Exclude a specific application from the applications whose contents is
  145. output. For example, to specifically exclude the `auth` application from
  146. the output, you would call::
  147. django-admin.py dumpdata --exclude=auth
  148. If you want to exclude multiple applications, use multiple ``--exclude``
  149. directives::
  150. django-admin.py dumpdata --exclude=auth --exclude=contenttype
  151. .. django-admin-option:: --format <fmt>
  152. By default, ``dumpdata`` will format its output in JSON, but you can use the
  153. ``--format`` option to specify another format. Currently supported formats
  154. are listed in :ref:`serialization-formats`.
  155. .. django-admin-option:: --indent <num>
  156. By default, ``dumpdata`` will output all data on a single line. This isn't
  157. easy for humans to read, so you can use the ``--indent`` option to
  158. pretty-print the output with a number of indentation spaces.
  159. flush
  160. -----
  161. .. django-admin: flush
  162. Returns the database to the state it was in immediately after syncdb was
  163. executed. This means that all data will be removed from the database, any
  164. post-synchronization handlers will be re-executed, and the ``initial_data``
  165. fixture will be re-installed.
  166. The behavior of this command has changed in the Django development version.
  167. Previously, this command cleared *every* table in the database, including any
  168. table that Django didn't know about (i.e., tables that didn't have associated
  169. models and/or weren't in ``INSTALLED_APPS``). Now, the command only clears
  170. tables that are represented by Django models and are activated in
  171. ``INSTALLED_APPS``.
  172. .. django-admin-option:: --noinput
  173. Use the ``--noinput`` option to suppress all user prompting, such as "Are
  174. you sure?" confirmation messages. This is useful if ``django-admin.py`` is
  175. being executed as an unattended, automated script.
  176. inspectdb
  177. ---------
  178. Introspects the database tables in the database pointed-to by the
  179. ``DATABASE_NAME`` setting and outputs a Django model module (a ``models.py``
  180. file) to standard output.
  181. Use this if you have a legacy database with which you'd like to use Django.
  182. The script will inspect the database and create a model for each table within
  183. it.
  184. As you might expect, the created models will have an attribute for every field
  185. in the table. Note that ``inspectdb`` has a few special cases in its field-name
  186. output:
  187. * If ``inspectdb`` cannot map a column's type to a model field type, it'll
  188. use ``TextField`` and will insert the Python comment
  189. ``'This field type is a guess.'`` next to the field in the generated
  190. model.
  191. * If the database column name is a Python reserved word (such as
  192. ``'pass'``, ``'class'`` or ``'for'``), ``inspectdb`` will append
  193. ``'_field'`` to the attribute name. For example, if a table has a column
  194. ``'for'``, the generated model will have a field ``'for_field'``, with
  195. the ``db_column`` attribute set to ``'for'``. ``inspectdb`` will insert
  196. the Python comment
  197. ``'Field renamed because it was a Python reserved word.'`` next to the
  198. field.
  199. This feature is meant as a shortcut, not as definitive model generation. After
  200. you run it, you'll want to look over the generated models yourself to make
  201. customizations. In particular, you'll need to rearrange models' order, so that
  202. models that refer to other models are ordered properly.
  203. Primary keys are automatically introspected for PostgreSQL, MySQL and
  204. SQLite, in which case Django puts in the ``primary_key=True`` where
  205. needed.
  206. ``inspectdb`` works with PostgreSQL, MySQL and SQLite. Foreign-key detection
  207. only works in PostgreSQL and with certain types of MySQL tables.
  208. loaddata <fixture fixture ...>
  209. ------------------------------
  210. Searches for and loads the contents of the named fixture into the database.
  211. A *fixture* is a collection of files that contain the serialized contents of
  212. the database. Each fixture has a unique name, and the files that comprise the
  213. fixture can be distributed over multiple directories, in multiple applications.
  214. Django will search in three locations for fixtures:
  215. 1. In the ``fixtures`` directory of every installed application
  216. 2. In any directory named in the ``FIXTURE_DIRS`` setting
  217. 3. In the literal path named by the fixture
  218. Django will load any and all fixtures it finds in these locations that match
  219. the provided fixture names.
  220. If the named fixture has a file extension, only fixtures of that type
  221. will be loaded. For example::
  222. django-admin.py loaddata mydata.json
  223. would only load JSON fixtures called ``mydata``. The fixture extension
  224. must correspond to the registered name of a serializer (e.g., ``json`` or
  225. ``xml``).
  226. If you omit the extension, Django will search all available fixture types
  227. for a matching fixture. For example::
  228. django-admin.py loaddata mydata
  229. would look for any fixture of any fixture type called ``mydata``. If a fixture
  230. directory contained ``mydata.json``, that fixture would be loaded
  231. as a JSON fixture. However, if two fixtures with the same name but different
  232. fixture type are discovered (for example, if ``mydata.json`` and
  233. ``mydata.xml`` were found in the same fixture directory), fixture
  234. installation will be aborted, and any data installed in the call to
  235. ``loaddata`` will be removed from the database.
  236. The fixtures that are named can include directory components. These
  237. directories will be included in the search path. For example::
  238. django-admin.py loaddata foo/bar/mydata.json
  239. would search ``<appname>/fixtures/foo/bar/mydata.json`` for each installed
  240. application, ``<dirname>/foo/bar/mydata.json`` for each directory in
  241. ``FIXTURE_DIRS``, and the literal path ``foo/bar/mydata.json``.
  242. Note that the order in which fixture files are processed is undefined. However,
  243. all fixture data is installed as a single transaction, so data in
  244. one fixture can reference data in another fixture. If the database backend
  245. supports row-level constraints, these constraints will be checked at the
  246. end of the transaction.
  247. The ``dumpdata`` command can be used to generate input for ``loaddata``.
  248. .. admonition:: MySQL and Fixtures
  249. Unfortunately, MySQL isn't capable of completely supporting all the
  250. features of Django fixtures. If you use MyISAM tables, MySQL doesn't
  251. support transactions or constraints, so you won't get a rollback if
  252. multiple transaction files are found, or validation of fixture data.
  253. If you use InnoDB tables, you won't be able to have any forward
  254. references in your data files - MySQL doesn't provide a mechanism to
  255. defer checking of row constraints until a transaction is committed.
  256. --verbosity
  257. ~~~~~~~~~~~
  258. Use ``--verbosity`` to specify the amount of notification and debug information
  259. that ``django-admin.py`` should print to the console.
  260. * ``0`` means no output.
  261. * ``1`` means normal output (default).
  262. * ``2`` means verbose output.
  263. Example usage::
  264. django-admin.py loaddata --verbosity=2
  265. makemessages
  266. ------------
  267. **New in Django development version**
  268. Runs over the entire source tree of the current directory and pulls out all
  269. strings marked for translation. It creates (or updates) a message file in the
  270. conf/locale (in the django tree) or locale (for project and application)
  271. directory. After making changes to the messages files you need to compile them
  272. with ``compilemessages`` for use with the builtin gettext support. See the
  273. :ref:`i18n documentation <how-to-create-language-files>` for details.
  274. --all
  275. ~~~~~
  276. Use the ``--all`` or ``-a`` option to update the message files for all
  277. available languages.
  278. Example usage::
  279. django-admin.py makemessages --all
  280. --extension
  281. ~~~~~~~~~~~
  282. Use the ``--extension`` or ``-e`` option to specify a list of file extensions
  283. to examine (default: ".html").
  284. Example usage::
  285. django-admin.py makemessages --locale=de --extension xhtml
  286. Separate multiple extensions with commas or use -e or --extension multiple times::
  287. django-admin.py makemessages --locale=de --extension=html,txt --extension xml
  288. --locale
  289. ~~~~~~~~
  290. Use the ``--locale`` or ``-l`` option to specify the locale to process.
  291. Example usage::
  292. django-admin.py makemessages --locale=br_PT
  293. --domain
  294. ~~~~~~~~
  295. Use the ``--domain`` or ``-d`` option to change the domain of the messages files.
  296. Currently supported:
  297. * ``django`` for all ``*.py`` and ``*.html`` files (default)
  298. * ``djangojs`` for ``*.js`` files
  299. --verbosity
  300. ~~~~~~~~~~~
  301. Use ``--verbosity`` or ``-v`` to specify the amount of notification and debug
  302. information that ``django-admin.py`` should print to the console.
  303. * ``0`` means no output.
  304. * ``1`` means normal output (default).
  305. * ``2`` means verbose output.
  306. Example usage::
  307. django-admin.py makemessages --verbosity=2
  308. reset <appname appname ...>
  309. ---------------------------
  310. Executes the equivalent of ``sqlreset`` for the given app name(s).
  311. --noinput
  312. ~~~~~~~~~
  313. Use the ``--noinput`` option to suppress all user prompting, such as
  314. "Are you sure?" confirmation messages. This is useful if ``django-admin.py``
  315. is being executed as an unattended, automated script.
  316. runfcgi [options]
  317. -----------------
  318. Starts a set of FastCGI processes suitable for use with any Web server that
  319. supports the FastCGI protocol. See the :ref:`FastCGI deployment documentation
  320. <howto-deployment-fastcgi>` for details. Requires the Python FastCGI module from
  321. `flup`_.
  322. .. _flup: http://www.saddi.com/software/flup/
  323. runserver [optional port number, or ipaddr:port]
  324. ------------------------------------------------
  325. Starts a lightweight development Web server on the local machine. By default,
  326. the server runs on port 8000 on the IP address 127.0.0.1. You can pass in an
  327. IP address and port number explicitly.
  328. If you run this script as a user with normal privileges (recommended), you
  329. might not have access to start a port on a low port number. Low port numbers
  330. are reserved for the superuser (root).
  331. DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through
  332. security audits or performance tests. (And that's how it's gonna stay. We're in
  333. the business of making Web frameworks, not Web servers, so improving this
  334. server to be able to handle a production environment is outside the scope of
  335. Django.)
  336. The development server automatically reloads Python code for each request, as
  337. needed. You don't need to restart the server for code changes to take effect.
  338. When you start the server, and each time you change Python code while the
  339. server is running, the server will validate all of your installed models. (See
  340. the ``validate`` command below.) If the validator finds errors, it will print
  341. them to standard output, but it won't stop the server.
  342. You can run as many servers as you want, as long as they're on separate ports.
  343. Just execute ``django-admin.py runserver`` more than once.
  344. Note that the default IP address, 127.0.0.1, is not accessible from other
  345. machines on your network. To make your development server viewable to other
  346. machines on the network, use its own IP address (e.g. ``192.168.2.1``) or
  347. ``0.0.0.0``.
  348. --adminmedia
  349. ~~~~~~~~~~~~
  350. Use the ``--adminmedia`` option to tell Django where to find the various CSS
  351. and JavaScript files for the Django admin interface. Normally, the development
  352. server serves these files out of the Django source tree magically, but you'd
  353. want to use this if you made any changes to those files for your own site.
  354. Example usage::
  355. django-admin.py runserver --adminmedia=/tmp/new-admin-style/
  356. --noreload
  357. ~~~~~~~~~~
  358. Use the ``--noreload`` option to disable the use of the auto-reloader. This
  359. means any Python code changes you make while the server is running will *not*
  360. take effect if the particular Python modules have already been loaded into
  361. memory.
  362. Example usage::
  363. django-admin.py runserver --noreload
  364. Examples of using different ports and addresses
  365. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  366. Port 8000 on IP address 127.0.0.1::
  367. django-admin.py runserver
  368. Port 8000 on IP address 1.2.3.4::
  369. django-admin.py runserver 1.2.3.4:8000
  370. Port 7000 on IP address 127.0.0.1::
  371. django-admin.py runserver 7000
  372. Port 7000 on IP address 1.2.3.4::
  373. django-admin.py runserver 1.2.3.4:7000
  374. Serving static files with the development server
  375. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  376. By default, the development server doesn't serve any static files for your site
  377. (such as CSS files, images, things under ``MEDIA_URL`` and so forth). If
  378. you want to configure Django to serve static media, read :ref:`howto-static-files`.
  379. Turning off auto-reload
  380. ~~~~~~~~~~~~~~~~~~~~~~~
  381. To disable auto-reloading of code while the development server is running, use the
  382. ``--noreload`` option, like so::
  383. django-admin.py runserver --noreload
  384. shell
  385. -----
  386. Starts the Python interactive interpreter.
  387. Django will use IPython_, if it's installed. If you have IPython installed and
  388. want to force use of the "plain" Python interpreter, use the ``--plain``
  389. option, like so::
  390. django-admin.py shell --plain
  391. .. _IPython: http://ipython.scipy.org/
  392. sql <appname appname ...>
  393. -------------------------
  394. Prints the CREATE TABLE SQL statements for the given app name(s).
  395. sqlall <appname appname ...>
  396. ----------------------------
  397. Prints the CREATE TABLE and initial-data SQL statements for the given app name(s).
  398. Refer to the description of ``sqlcustom`` for an explanation of how to
  399. specify initial data.
  400. sqlclear <appname appname ...>
  401. ------------------------------
  402. Prints the DROP TABLE SQL statements for the given app name(s).
  403. sqlcustom <appname appname ...>
  404. -------------------------------
  405. Prints the custom SQL statements for the given app name(s).
  406. For each model in each specified app, this command looks for the file
  407. ``<appname>/sql/<modelname>.sql``, where ``<appname>`` is the given app name and
  408. ``<modelname>`` is the model's name in lowercase. For example, if you have an
  409. app ``news`` that includes a ``Story`` model, ``sqlcustom`` will attempt
  410. to read a file ``news/sql/story.sql`` and append it to the output of this
  411. command.
  412. Each of the SQL files, if given, is expected to contain valid SQL. The SQL
  413. files are piped directly into the database after all of the models'
  414. table-creation statements have been executed. Use this SQL hook to make any
  415. table modifications, or insert any SQL functions into the database.
  416. Note that the order in which the SQL files are processed is undefined.
  417. sqlflush
  418. --------
  419. Prints the SQL statements that would be executed for the `flush`_ command.
  420. sqlindexes <appname appname ...>
  421. --------------------------------
  422. Prints the CREATE INDEX SQL statements for the given app name(s).
  423. sqlreset <appname appname ...>
  424. ------------------------------
  425. Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given app name(s).
  426. sqlsequencereset <appname appname ...>
  427. --------------------------------------
  428. Prints the SQL statements for resetting sequences for the given app name(s).
  429. See http://simon.incutio.com/archive/2004/04/21/postgres for more information.
  430. startapp <appname>
  431. ------------------
  432. Creates a Django app directory structure for the given app name in the current
  433. directory.
  434. startproject <projectname>
  435. --------------------------
  436. Creates a Django project directory structure for the given project name in the
  437. current directory.
  438. syncdb
  439. ------
  440. Creates the database tables for all apps in ``INSTALLED_APPS`` whose tables
  441. have not already been created.
  442. Use this command when you've added new applications to your project and want to
  443. install them in the database. This includes any apps shipped with Django that
  444. might be in ``INSTALLED_APPS`` by default. When you start a new project, run
  445. this command to install the default apps.
  446. .. admonition:: Syncdb will not alter existing tables
  447. ``syncdb`` will only create tables for models which have not yet been
  448. installed. It will *never* issue ``ALTER TABLE`` statements to match
  449. changes made to a model class after installation. Changes to model classes
  450. and database schemas often involve some form of ambiguity and, in those
  451. cases, Django would have to guess at the correct changes to make. There is
  452. a risk that critical data would be lost in the process.
  453. If you have made changes to a model and wish to alter the database tables
  454. to match, use the ``sql`` command to display the new SQL structure and
  455. compare that to your existing table schema to work out the changes.
  456. If you're installing the ``django.contrib.auth`` application, ``syncdb`` will
  457. give you the option of creating a superuser immediately.
  458. ``syncdb`` will also search for and install any fixture named ``initial_data``
  459. with an appropriate extension (e.g. ``json`` or ``xml``). See the
  460. documentation for ``loaddata`` for details on the specification of fixture
  461. data files.
  462. --verbosity
  463. ~~~~~~~~~~~
  464. Use ``--verbosity`` to specify the amount of notification and debug information
  465. that ``django-admin.py`` should print to the console.
  466. * ``0`` means no output.
  467. * ``1`` means normal output (default).
  468. * ``2`` means verbose output.
  469. Example usage::
  470. django-admin.py syncdb --verbosity=2
  471. --noinput
  472. ~~~~~~~~~
  473. Use the ``--noinput`` option to suppress all user prompting, such as
  474. "Are you sure?" confirmation messages. This is useful if ``django-admin.py``
  475. is being executed as an unattended, automated script.
  476. test
  477. ----
  478. Runs tests for all installed models. See :ref:`topics-testing` for more
  479. information.
  480. --noinput
  481. ~~~~~~~~~
  482. Use the ``--noinput`` option to suppress all user prompting, such as
  483. "Are you sure?" confirmation messages. This is useful if ``django-admin.py``
  484. is being executed as an unattended, automated script.
  485. --verbosity
  486. ~~~~~~~~~~~
  487. Use ``--verbosity`` to specify the amount of notification and debug information
  488. that ``django-admin.py`` should print to the console.
  489. * ``0`` means no output.
  490. * ``1`` means normal output (default).
  491. * ``2`` means verbose output.
  492. Example usage::
  493. django-admin.py test --verbosity=2
  494. testserver <fixture fixture ...>
  495. --------------------------------
  496. **New in Django development version**
  497. Runs a Django development server (as in ``runserver``) using data from the
  498. given fixture(s).
  499. For example, this command::
  500. django-admin.py testserver mydata.json
  501. ...would perform the following steps:
  502. 1. Create a test database, as described in :ref:`topics-testing`.
  503. 2. Populate the test database with fixture data from the given fixtures.
  504. (For more on fixtures, see the documentation for ``loaddata`` above.)
  505. 3. Runs the Django development server (as in ``runserver``), pointed at
  506. this newly created test database instead of your production database.
  507. This is useful in a number of ways:
  508. * When you're writing :ref:`unit tests <topics-testing>` of how your views
  509. act with certain fixture data, you can use ``testserver`` to interact with
  510. the views in a Web browser, manually.
  511. * Let's say you're developing your Django application and have a "pristine"
  512. copy of a database that you'd like to interact with. You can dump your
  513. database to a fixture (using the ``dumpdata`` command, explained above),
  514. then use ``testserver`` to run your Web application with that data. With
  515. this arrangement, you have the flexibility of messing up your data
  516. in any way, knowing that whatever data changes you're making are only
  517. being made to a test database.
  518. Note that this server does *not* automatically detect changes to your Python
  519. source code (as ``runserver`` does). It does, however, detect changes to
  520. templates.
  521. --addrport [port number or ipaddr:port]
  522. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  523. Use ``--addrport`` to specify a different port, or IP address and port, from
  524. the default of 127.0.0.1:8000. This value follows exactly the same format and
  525. serves exactly the same function as the argument to the ``runserver`` subcommand.
  526. Examples:
  527. To run the test server on port 7000 with ``fixture1`` and ``fixture2``::
  528. django-admin.py testserver --addrport 7000 fixture1 fixture2
  529. django-admin.py testserver fixture1 fixture2 --addrport 7000
  530. (The above statements are equivalent. We include both of them to demonstrate
  531. that it doesn't matter whether the options come before or after the fixture
  532. arguments.)
  533. To run on 1.2.3.4:7000 with a ``test`` fixture::
  534. django-admin.py testserver --addrport 1.2.3.4:7000 test
  535. --verbosity
  536. ~~~~~~~~~~~
  537. Use ``--verbosity`` to specify the amount of notification and debug information
  538. that ``django-admin.py`` should print to the console.
  539. * ``0`` means no output.
  540. * ``1`` means normal output (default).
  541. * ``2`` means verbose output.
  542. Example usage::
  543. django-admin.py testserver --verbosity=2
  544. validate
  545. --------
  546. Validates all installed models (according to the ``INSTALLED_APPS`` setting)
  547. and prints validation errors to standard output.
  548. Default options
  549. ===============
  550. Although some subcommands may allow their own custom options, every subcommand
  551. allows for the following options:
  552. --pythonpath
  553. ------------
  554. Example usage::
  555. django-admin.py syncdb --pythonpath='/home/djangoprojects/myproject'
  556. Adds the given filesystem path to the Python `import search path`_. If this
  557. isn't provided, ``django-admin.py`` will use the ``PYTHONPATH`` environment
  558. variable.
  559. Note that this option is unnecessary in ``manage.py``, because it takes care of
  560. setting the Python path for you.
  561. .. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html
  562. --settings
  563. ----------
  564. Example usage::
  565. django-admin.py syncdb --settings=mysite.settings
  566. Explicitly specifies the settings module to use. The settings module should be
  567. in Python package syntax, e.g. ``mysite.settings``. If this isn't provided,
  568. ``django-admin.py`` will use the ``DJANGO_SETTINGS_MODULE`` environment
  569. variable.
  570. Note that this option is unnecessary in ``manage.py``, because it uses
  571. ``settings.py`` from the current project by default.
  572. --traceback
  573. -----------
  574. Example usage::
  575. django-admin.py syncdb --traceback
  576. By default, ``django-admin.py`` will show a simple error message whenever an
  577. error occurs. If you specify ``--traceback``, ``django-admin.py`` will
  578. output a full stack trace whenever an exception is raised.
  579. Extra niceties
  580. ==============
  581. Syntax coloring
  582. ---------------
  583. The ``django-admin.py`` / ``manage.py`` commands that output SQL to standard
  584. output will use pretty color-coded output if your terminal supports
  585. ANSI-colored output. It won't use the color codes if you're piping the
  586. command's output to another program.
  587. Bash completion
  588. ---------------
  589. If you use the Bash shell, consider installing the Django bash completion
  590. script, which lives in ``extras/django_bash_completion`` in the Django
  591. distribution. It enables tab-completion of ``django-admin.py`` and
  592. ``manage.py`` commands, so you can, for instance...
  593. * Type ``django-admin.py``.
  594. * Press [TAB] to see all available options.
  595. * Type ``sql``, then [TAB], to see all available options whose names start
  596. with ``sql``.
  597. See :ref:`howto-custom-management-commands` for how to add customized actions.