Django

Code

root/django/branches/gis/docs/django-admin.txt

Revision 8215, 30.0 kB (checked in by jbronn, 4 months ago)

gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.

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