django-admin.txt 28 KB

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