django-admin.txt 29 KB

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