django-admin.txt 28 KB

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