django-admin.txt 30 KB

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