forked from django/django
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdjango-admin.txt
2003 lines (1336 loc) · 69.1 KB
/
django-admin.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
==================================
``django-admin`` and ``manage.py``
==================================
``django-admin`` is Django's command-line utility for administrative tasks.
This document outlines all it can do.
In addition, ``manage.py`` is automatically created in each Django project. It
does the same thing as ``django-admin`` but also sets the
:envvar:`DJANGO_SETTINGS_MODULE` environment variable so that it points to your
project's ``settings.py`` file.
The ``django-admin`` script should be on your system path if you installed
Django via ``pip``. If it's not in your path, ensure you have your virtual
environment activated.
Generally, when working on a single Django project, it's easier to use
``manage.py`` than ``django-admin``. If you need to switch between multiple
Django settings files, use ``django-admin`` with
:envvar:`DJANGO_SETTINGS_MODULE` or the :option:`--settings` command line
option.
The command-line examples throughout this document use ``django-admin`` to
be consistent, but any example can use ``manage.py`` or ``python -m django``
just as well.
Usage
=====
.. console::
$ django-admin <command> [options]
$ manage.py <command> [options]
$ python -m django <command> [options]
``command`` should be one of the commands listed in this document.
``options``, which is optional, should be zero or more of the options available
for the given command.
Getting runtime help
--------------------
.. django-admin:: help
Run ``django-admin help`` to display usage information and a list of the
commands provided by each application.
Run ``django-admin help --commands`` to display a list of all available
commands.
Run ``django-admin help <command>`` to display a description of the given
command and a list of its available options.
App names
---------
Many commands take a list of "app names." An "app name" is the basename of
the package containing your models. For example, if your :setting:`INSTALLED_APPS`
contains the string ``'mysite.blog'``, the app name is ``blog``.
Determining the version
-----------------------
.. django-admin:: version
Run ``django-admin version`` to display the current Django version.
The output follows the schema described in :pep:`440`::
1.4.dev17026
1.4a1
1.4
Displaying debug output
-----------------------
.. program:: None
Use :option:`--verbosity` to specify the amount of notification and debug
information that ``django-admin`` prints to the console.
Available commands
==================
``check``
---------
.. django-admin:: check [app_label [app_label ...]]
Uses the :doc:`system check framework </ref/checks>` to inspect the entire
Django project for common problems.
By default, all apps will be checked. You can check a subset of apps by
providing a list of app labels as arguments::
django-admin check auth admin myapp
If you do not specify any app, all apps will be checked.
.. django-admin-option:: --tag TAGS, -t TAGS
The system check framework performs many different types of checks that are
:ref:`categorized with tags <system-check-builtin-tags>`. You can use these
tags to restrict the checks performed to just those in a particular category.
For example, to perform only models and compatibility checks, run::
django-admin check --tag models --tag compatibility
.. django-admin-option:: --database DATABASE
.. versionadded:: 3.1
Specifies the database to run checks requiring database access::
django-admin check --database default --database other
By default, these checks will not be run.
.. django-admin-option:: --list-tags
Lists all available tags.
.. django-admin-option:: --deploy
Activates some additional checks that are only relevant in a deployment setting.
You can use this option in your local development environment, but since your
local development settings module may not have many of your production settings,
you will probably want to point the ``check`` command at a different settings
module, either by setting the ``DJANGO_SETTINGS_MODULE`` environment variable,
or by passing the ``--settings`` option::
django-admin check --deploy --settings=production_settings
Or you could run it directly on a production or staging deployment to verify
that the correct settings are in use (omitting ``--settings``). You could even
make it part of your integration test suite.
.. django-admin-option:: --fail-level {CRITICAL,ERROR,WARNING,INFO,DEBUG}
Specifies the message level that will cause the command to exit with a non-zero
status. Default is ``ERROR``.
``compilemessages``
-------------------
.. django-admin:: compilemessages
Compiles ``.po`` files created by :djadmin:`makemessages` to ``.mo`` files for
use with the built-in gettext support. See :doc:`/topics/i18n/index`.
.. django-admin-option:: --locale LOCALE, -l LOCALE
Specifies the locale(s) to process. If not provided, all locales are processed.
.. django-admin-option:: --exclude EXCLUDE, -x EXCLUDE
Specifies the locale(s) to exclude from processing. If not provided, no locales
are excluded.
.. django-admin-option:: --use-fuzzy, -f
Includes fuzzy translations into compiled files.
Example usage::
django-admin compilemessages --locale=pt_BR
django-admin compilemessages --locale=pt_BR --locale=fr -f
django-admin compilemessages -l pt_BR
django-admin compilemessages -l pt_BR -l fr --use-fuzzy
django-admin compilemessages --exclude=pt_BR
django-admin compilemessages --exclude=pt_BR --exclude=fr
django-admin compilemessages -x pt_BR
django-admin compilemessages -x pt_BR -x fr
.. django-admin-option:: --ignore PATTERN, -i PATTERN
.. versionadded:: 3.0
Ignores directories matching the given :mod:`glob`-style pattern. Use
multiple times to ignore more.
Example usage::
django-admin compilemessages --ignore=cache --ignore=outdated/*/locale
``createcachetable``
--------------------
.. django-admin:: createcachetable
Creates the cache tables for use with the database cache backend using the
information from your settings file. See :doc:`/topics/cache` for more
information.
.. django-admin-option:: --database DATABASE
Specifies the database in which the cache table(s) will be created. Defaults to
``default``.
.. django-admin-option:: --dry-run
Prints the SQL that would be run without actually running it, so you can
customize it or use the migrations framework.
``dbshell``
-----------
.. django-admin:: dbshell
Runs the command-line client for the database engine specified in your
:setting:`ENGINE <DATABASE-ENGINE>` setting, with the connection parameters
specified in your :setting:`USER`, :setting:`PASSWORD`, etc., settings.
* For PostgreSQL, this runs the ``psql`` command-line client.
* For MySQL, this runs the ``mysql`` command-line client.
* For SQLite, this runs the ``sqlite3`` command-line client.
* For Oracle, this runs the ``sqlplus`` command-line client.
This command assumes the programs are on your ``PATH`` so that a call to
the program name (``psql``, ``mysql``, ``sqlite3``, ``sqlplus``) will find the
program in the right place. There's no way to specify the location of the
program manually.
.. django-admin-option:: --database DATABASE
Specifies the database onto which to open a shell. Defaults to ``default``.
.. note::
Be aware that not all options set in the :setting:`OPTIONS` part of your
database configuration in :setting:`DATABASES` are passed to the
command-line client, e.g. ``'isolation_level'``.
``diffsettings``
----------------
.. django-admin:: diffsettings
Displays differences between the current settings file and Django's default
settings (or another settings file specified by :option:`--default`).
Settings that don't appear in the defaults are followed by ``"###"``. For
example, the default settings don't define :setting:`ROOT_URLCONF`, so
:setting:`ROOT_URLCONF` is followed by ``"###"`` in the output of
``diffsettings``.
.. django-admin-option:: --all
Displays all settings, even if they have Django's default value. Such settings
are prefixed by ``"###"``.
.. django-admin-option:: --default MODULE
The settings module to compare the current settings against. Leave empty to
compare against Django's default settings.
.. django-admin-option:: --output {hash,unified}
Specifies the output format. Available values are ``hash`` and ``unified``.
``hash`` is the default mode that displays the output that's described above.
``unified`` displays the output similar to ``diff -u``. Default settings are
prefixed with a minus sign, followed by the changed setting prefixed with a
plus sign.
``dumpdata``
------------
.. django-admin:: dumpdata [app_label[.ModelName] [app_label[.ModelName] ...]]
Outputs to standard output all data in the database associated with the named
application(s).
If no application name is provided, all installed applications will be dumped.
The output of ``dumpdata`` can be used as input for :djadmin:`loaddata`.
Note that ``dumpdata`` uses the default manager on the model for selecting the
records to dump. If you're using a :ref:`custom manager <custom-managers>` as
the default manager and it filters some of the available records, not all of the
objects will be dumped.
.. django-admin-option:: --all, -a
Uses Django's base manager, dumping records which might otherwise be filtered
or modified by a custom manager.
.. django-admin-option:: --format FORMAT
Specifies the serialization format of the output. Defaults to JSON. Supported
formats are listed in :ref:`serialization-formats`.
.. django-admin-option:: --indent INDENT
Specifies the number of indentation spaces to use in the output. Defaults to
``None`` which displays all data on single line.
.. django-admin-option:: --exclude EXCLUDE, -e EXCLUDE
Prevents specific applications or models (specified in the form of
``app_label.ModelName``) from being dumped. If you specify a model name, the
output will be restricted to that model, rather than the entire application.
You can also mix application names and model names.
If you want to exclude multiple applications, pass ``--exclude`` more than
once::
django-admin dumpdata --exclude=auth --exclude=contenttypes
.. django-admin-option:: --database DATABASE
Specifies the database from which data will be dumped. Defaults to ``default``.
.. django-admin-option:: --natural-foreign
Uses the ``natural_key()`` model method to serialize any foreign key and
many-to-many relationship to objects of the type that defines the method. If
you're dumping ``contrib.auth`` ``Permission`` objects or
``contrib.contenttypes`` ``ContentType`` objects, you should probably use this
flag. See the :ref:`natural keys <topics-serialization-natural-keys>`
documentation for more details on this and the next option.
.. django-admin-option:: --natural-primary
Omits the primary key in the serialized data of this object since it can be
calculated during deserialization.
.. django-admin-option:: --pks PRIMARY_KEYS
Outputs only the objects specified by a comma separated list of primary keys.
This is only available when dumping one model. By default, all the records of
the model are output.
.. django-admin-option:: --output OUTPUT, -o OUTPUT
Specifies a file to write the serialized data to. By default, the data goes to
standard output.
When this option is set and ``--verbosity`` is greater than 0 (the default), a
progress bar is shown in the terminal.
``flush``
---------
.. django-admin:: flush
Removes all data from the database and re-executes any post-synchronization
handlers. The table of which migrations have been applied is not cleared.
If you would rather start from an empty database and re-run all migrations, you
should drop and recreate the database and then run :djadmin:`migrate` instead.
.. django-admin-option:: --noinput, --no-input
Suppresses all user prompts.
.. django-admin-option:: --database DATABASE
Specifies the database to flush. Defaults to ``default``.
``inspectdb``
-------------
.. django-admin:: inspectdb [table [table ...]]
Introspects the database tables in the database pointed-to by the
:setting:`NAME` setting and outputs a Django model module (a ``models.py``
file) to standard output.
You may choose what tables or views to inspect by passing their names as
arguments. If no arguments are provided, models are created for views only if
the :option:`--include-views` option is used. Models for partition tables are
created on PostgreSQL if the :option:`--include-partitions` option is used.
Use this if you have a legacy database with which you'd like to use Django.
The script will inspect the database and create a model for each table within
it.
As you might expect, the created models will have an attribute for every field
in the table. Note that ``inspectdb`` has a few special cases in its field-name
output:
* If ``inspectdb`` cannot map a column's type to a model field type, it'll
use ``TextField`` and will insert the Python comment
``'This field type is a guess.'`` next to the field in the generated
model. The recognized fields may depend on apps listed in
:setting:`INSTALLED_APPS`. For example, :mod:`django.contrib.postgres` adds
recognition for several PostgreSQL-specific field types.
* If the database column name is a Python reserved word (such as
``'pass'``, ``'class'`` or ``'for'``), ``inspectdb`` will append
``'_field'`` to the attribute name. For example, if a table has a column
``'for'``, the generated model will have a field ``'for_field'``, with
the ``db_column`` attribute set to ``'for'``. ``inspectdb`` will insert
the Python comment
``'Field renamed because it was a Python reserved word.'`` next to the
field.
This feature is meant as a shortcut, not as definitive model generation. After
you run it, you'll want to look over the generated models yourself to make
customizations. In particular, you'll need to rearrange models' order, so that
models that refer to other models are ordered properly.
Django doesn't create database defaults when a
:attr:`~django.db.models.Field.default` is specified on a model field.
Similarly, database defaults aren't translated to model field defaults or
detected in any fashion by ``inspectdb``.
By default, ``inspectdb`` creates unmanaged models. That is, ``managed = False``
in the model's ``Meta`` class tells Django not to manage each table's creation,
modification, and deletion. If you do want to allow Django to manage the
table's lifecycle, you'll need to change the
:attr:`~django.db.models.Options.managed` option to ``True`` (or remove
it because ``True`` is its default value).
Database-specific notes
~~~~~~~~~~~~~~~~~~~~~~~
Oracle
^^^^^^
* Models are created for materialized views if :option:`--include-views` is
used.
PostgreSQL
^^^^^^^^^^
* Models are created for foreign tables.
* Models are created for materialized views if
:option:`--include-views` is used.
* Models are created for partition tables if
:option:`--include-partitions` is used.
.. django-admin-option:: --database DATABASE
Specifies the database to introspect. Defaults to ``default``.
.. django-admin-option:: --include-partitions
If this option is provided, models are also created for partitions.
Only support for PostgreSQL is implemented.
.. django-admin-option:: --include-views
If this option is provided, models are also created for database views.
``loaddata``
------------
.. django-admin:: loaddata fixture [fixture ...]
Searches for and loads the contents of the named fixture into the database.
.. django-admin-option:: --database DATABASE
Specifies the database into which the data will be loaded. Defaults to
``default``.
.. django-admin-option:: --ignorenonexistent, -i
Ignores fields and models that may have been removed since the fixture was
originally generated.
.. django-admin-option:: --app APP_LABEL
Specifies a single app to look for fixtures in rather than looking in all apps.
.. django-admin-option:: --format FORMAT
Specifies the :ref:`serialization format <serialization-formats>` (e.g.,
``json`` or ``xml``) for fixtures :ref:`read from stdin
<loading-fixtures-stdin>`.
.. django-admin-option:: --exclude EXCLUDE, -e EXCLUDE
Excludes loading the fixtures from the given applications and/or models (in the
form of ``app_label`` or ``app_label.ModelName``). Use the option multiple
times to exclude more than one app or model.
What's a "fixture"?
~~~~~~~~~~~~~~~~~~~
A *fixture* is a collection of files that contain the serialized contents of
the database. Each fixture has a unique name, and the files that comprise the
fixture can be distributed over multiple directories, in multiple applications.
Django will search in three locations for fixtures:
1. In the ``fixtures`` directory of every installed application
2. In any directory named in the :setting:`FIXTURE_DIRS` setting
3. In the literal path named by the fixture
Django will load any and all fixtures it finds in these locations that match
the provided fixture names.
If the named fixture has a file extension, only fixtures of that type
will be loaded. For example::
django-admin loaddata mydata.json
would only load JSON fixtures called ``mydata``. The fixture extension
must correspond to the registered name of a
:ref:`serializer <serialization-formats>` (e.g., ``json`` or ``xml``).
If you omit the extensions, Django will search all available fixture types
for a matching fixture. For example::
django-admin loaddata mydata
would look for any fixture of any fixture type called ``mydata``. If a fixture
directory contained ``mydata.json``, that fixture would be loaded
as a JSON fixture.
The fixtures that are named can include directory components. These
directories will be included in the search path. For example::
django-admin loaddata foo/bar/mydata.json
would search ``<app_label>/fixtures/foo/bar/mydata.json`` for each installed
application, ``<dirname>/foo/bar/mydata.json`` for each directory in
:setting:`FIXTURE_DIRS`, and the literal path ``foo/bar/mydata.json``.
When fixture files are processed, the data is saved to the database as is.
Model defined :meth:`~django.db.models.Model.save` methods are not called, and
any :data:`~django.db.models.signals.pre_save` or
:data:`~django.db.models.signals.post_save` signals will be called with
``raw=True`` since the instance only contains attributes that are local to the
model. You may, for example, want to disable handlers that access
related fields that aren't present during fixture loading and would otherwise
raise an exception::
from django.db.models.signals import post_save
from .models import MyModel
def my_handler(**kwargs):
# disable the handler during fixture loading
if kwargs['raw']:
return
...
post_save.connect(my_handler, sender=MyModel)
You could also write a decorator to encapsulate this logic::
from functools import wraps
def disable_for_loaddata(signal_handler):
"""
Decorator that turns off signal handlers when loading fixture data.
"""
@wraps(signal_handler)
def wrapper(*args, **kwargs):
if kwargs['raw']:
return
signal_handler(*args, **kwargs)
return wrapper
@disable_for_loaddata
def my_handler(**kwargs):
...
Just be aware that this logic will disable the signals whenever fixtures are
deserialized, not just during ``loaddata``.
Note that the order in which fixture files are processed is undefined. However,
all fixture data is installed as a single transaction, so data in
one fixture can reference data in another fixture. If the database backend
supports row-level constraints, these constraints will be checked at the
end of the transaction.
The :djadmin:`dumpdata` command can be used to generate input for ``loaddata``.
Compressed fixtures
~~~~~~~~~~~~~~~~~~~
Fixtures may be compressed in ``zip``, ``gz``, or ``bz2`` format. For example::
django-admin loaddata mydata.json
would look for any of ``mydata.json``, ``mydata.json.zip``,
``mydata.json.gz``, or ``mydata.json.bz2``. The first file contained within a
zip-compressed archive is used.
Note that if two fixtures with the same name but different
fixture type are discovered (for example, if ``mydata.json`` and
``mydata.xml.gz`` were found in the same fixture directory), fixture
installation will be aborted, and any data installed in the call to
``loaddata`` will be removed from the database.
.. admonition:: MySQL with MyISAM and fixtures
The MyISAM storage engine of MySQL doesn't support transactions or
constraints, so if you use MyISAM, you won't get validation of fixture
data, or a rollback if multiple transaction files are found.
Database-specific fixtures
~~~~~~~~~~~~~~~~~~~~~~~~~~
If you're in a multi-database setup, you might have fixture data that
you want to load onto one database, but not onto another. In this
situation, you can add a database identifier into the names of your fixtures.
For example, if your :setting:`DATABASES` setting has a 'master' database
defined, name the fixture ``mydata.master.json`` or
``mydata.master.json.gz`` and the fixture will only be loaded when you
specify you want to load data into the ``master`` database.
.. _loading-fixtures-stdin:
Loading fixtures from ``stdin``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can use a dash as the fixture name to load input from ``sys.stdin``. For
example::
django-admin loaddata --format=json -
When reading from ``stdin``, the :option:`--format <loaddata --format>` option
is required to specify the :ref:`serialization format <serialization-formats>`
of the input (e.g., ``json`` or ``xml``).
Loading from ``stdin`` is useful with standard input and output redirections.
For example::
django-admin dumpdata --format=json --database=test app_label.ModelName | django-admin loaddata --format=json --database=prod -
``makemessages``
----------------
.. django-admin:: makemessages
Runs over the entire source tree of the current directory and pulls out all
strings marked for translation. It creates (or updates) a message file in the
conf/locale (in the Django tree) or locale (for project and application)
directory. After making changes to the messages files you need to compile them
with :djadmin:`compilemessages` for use with the builtin gettext support. See
the :ref:`i18n documentation <how-to-create-language-files>` for details.
This command doesn't require configured settings. However, when settings aren't
configured, the command can't ignore the :setting:`MEDIA_ROOT` and
:setting:`STATIC_ROOT` directories or include :setting:`LOCALE_PATHS`.
.. django-admin-option:: --all, -a
Updates the message files for all available languages.
.. django-admin-option:: --extension EXTENSIONS, -e EXTENSIONS
Specifies a list of file extensions to examine (default: ``html``, ``txt``,
``py`` or ``js`` if :option:`--domain` is ``js``).
Example usage::
django-admin makemessages --locale=de --extension xhtml
Separate multiple extensions with commas or use ``-e`` or ``--extension``
multiple times::
django-admin makemessages --locale=de --extension=html,txt --extension xml
.. django-admin-option:: --locale LOCALE, -l LOCALE
Specifies the locale(s) to process.
.. django-admin-option:: --exclude EXCLUDE, -x EXCLUDE
Specifies the locale(s) to exclude from processing. If not provided, no locales
are excluded.
Example usage::
django-admin makemessages --locale=pt_BR
django-admin makemessages --locale=pt_BR --locale=fr
django-admin makemessages -l pt_BR
django-admin makemessages -l pt_BR -l fr
django-admin makemessages --exclude=pt_BR
django-admin makemessages --exclude=pt_BR --exclude=fr
django-admin makemessages -x pt_BR
django-admin makemessages -x pt_BR -x fr
.. django-admin-option:: --domain DOMAIN, -d DOMAIN
Specifies the domain of the messages files. Supported options are:
* ``django`` for all ``*.py``, ``*.html`` and ``*.txt`` files (default)
* ``djangojs`` for ``*.js`` files
.. django-admin-option:: --symlinks, -s
Follows symlinks to directories when looking for new translation strings.
Example usage::
django-admin makemessages --locale=de --symlinks
.. django-admin-option:: --ignore PATTERN, -i PATTERN
Ignores files or directories matching the given :mod:`glob`-style pattern. Use
multiple times to ignore more.
These patterns are used by default: ``'CVS'``, ``'.*'``, ``'*~'``, ``'*.pyc'``.
Example usage::
django-admin makemessages --locale=en_US --ignore=apps/* --ignore=secret/*.html
.. django-admin-option:: --no-default-ignore
Disables the default values of ``--ignore``.
.. django-admin-option:: --no-wrap
Disables breaking long message lines into several lines in language files.
.. django-admin-option:: --no-location
Suppresses writing '``#: filename:line``’ comment lines in language files.
Using this option makes it harder for technically skilled translators to
understand each message's context.
.. django-admin-option:: --add-location [{full,file,never}]
Controls ``#: filename:line`` comment lines in language files. If the option
is:
* ``full`` (the default if not given): the lines include both file name and
line number.
* ``file``: the line number is omitted.
* ``never``: the lines are suppressed (same as :option:`--no-location`).
Requires ``gettext`` 0.19 or newer.
.. django-admin-option:: --keep-pot
Prevents deleting the temporary ``.pot`` files generated before creating the
``.po`` file. This is useful for debugging errors which may prevent the final
language files from being created.
.. seealso::
See :ref:`customizing-makemessages` for instructions on how to customize
the keywords that :djadmin:`makemessages` passes to ``xgettext``.
``makemigrations``
------------------
.. django-admin:: makemigrations [app_label [app_label ...]]
Creates new migrations based on the changes detected to your models.
Migrations, their relationship with apps and more are covered in depth in
:doc:`the migrations documentation</topics/migrations>`.
Providing one or more app names as arguments will limit the migrations created
to the app(s) specified and any dependencies needed (the table at the other end
of a ``ForeignKey``, for example).
To add migrations to an app that doesn't have a ``migrations`` directory, run
``makemigrations`` with the app's ``app_label``.
.. django-admin-option:: --noinput, --no-input
Suppresses all user prompts. If a suppressed prompt cannot be resolved
automatically, the command will exit with error code 3.
.. django-admin-option:: --empty
Outputs an empty migration for the specified apps, for manual editing. This is
for advanced users and should not be used unless you are familiar with the
migration format, migration operations, and the dependencies between your
migrations.
.. django-admin-option:: --dry-run
Shows what migrations would be made without actually writing any migrations
files to disk. Using this option along with ``--verbosity 3`` will also show
the complete migrations files that would be written.
.. django-admin-option:: --merge
Enables fixing of migration conflicts.
.. django-admin-option:: --name NAME, -n NAME
Allows naming the generated migration(s) instead of using a generated name. The
name must be a valid Python :ref:`identifier <python:identifiers>`.
.. django-admin-option:: --no-header
Generate migration files without Django version and timestamp header.
.. django-admin-option:: --check
Makes ``makemigrations`` exit with a non-zero status when model changes without
migrations are detected.
``migrate``
-----------
.. django-admin:: migrate [app_label] [migration_name]
Synchronizes the database state with the current set of models and migrations.
Migrations, their relationship with apps and more are covered in depth in
:doc:`the migrations documentation</topics/migrations>`.
The behavior of this command changes depending on the arguments provided:
* No arguments: All apps have all of their migrations run.
* ``<app_label>``: The specified app has its migrations run, up to the most
recent migration. This may involve running other apps' migrations too, due
to dependencies.
* ``<app_label> <migrationname>``: Brings the database schema to a state where
the named migration is applied, but no later migrations in the same app are
applied. This may involve unapplying migrations if you have previously
migrated past the named migration. You can use a prefix of the migration
name, e.g. ``0001``, as long as it's unique for the given app name. Use the
name ``zero`` to migrate all the way back i.e. to revert all applied
migrations for an app.
.. warning::
When unapplying migrations, all dependent migrations will also be
unapplied, regardless of ``<app_label>``. You can use ``--plan`` to check
which migrations will be unapplied.
.. django-admin-option:: --database DATABASE
Specifies the database to migrate. Defaults to ``default``.
.. django-admin-option:: --fake
Marks the migrations up to the target one (following the rules above) as
applied, but without actually running the SQL to change your database schema.
This is intended for advanced users to manipulate the
current migration state directly if they're manually applying changes;
be warned that using ``--fake`` runs the risk of putting the migration state
table into a state where manual recovery will be needed to make migrations
run correctly.
.. django-admin-option:: --fake-initial
Allows Django to skip an app's initial migration if all database tables with
the names of all models created by all
:class:`~django.db.migrations.operations.CreateModel` operations in that
migration already exist. This option is intended for use when first running
migrations against a database that preexisted the use of migrations. This
option does not, however, check for matching database schema beyond matching
table names and so is only safe to use if you are confident that your existing
schema matches what is recorded in your initial migration.
.. django-admin-option:: --plan
Shows the migration operations that will be performed for the given ``migrate``
command.
.. django-admin-option:: --run-syncdb
Allows creating tables for apps without migrations. While this isn't
recommended, the migrations framework is sometimes too slow on large projects
with hundreds of models.
.. django-admin-option:: --noinput, --no-input
Suppresses all user prompts. An example prompt is asking about removing stale
content types.
.. django-admin-option:: --check
.. versionadded:: 3.1
Makes ``migrate`` exit with a non-zero status when unapplied migrations are
detected.
``runserver``
-------------
.. django-admin:: runserver [addrport]
Starts a lightweight development Web server on the local machine. By default,
the server runs on port 8000 on the IP address ``127.0.0.1``. You can pass in an
IP address and port number explicitly.
If you run this script as a user with normal privileges (recommended), you
might not have access to start a port on a low port number. Low port numbers
are reserved for the superuser (root).
This server uses the WSGI application object specified by the
:setting:`WSGI_APPLICATION` setting.
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through
security audits or performance tests. (And that's how it's gonna stay. We're in
the business of making Web frameworks, not Web servers, so improving this
server to be able to handle a production environment is outside the scope of
Django.)
The development server automatically reloads Python code for each request, as
needed. You don't need to restart the server for code changes to take effect.
However, some actions like adding files don't trigger a restart, so you'll
have to restart the server in these cases.
If you're using Linux or MacOS and install both `pywatchman`_ and the
`Watchman`_ service, kernel signals will be used to autoreload the server
(rather than polling file modification timestamps each second). This offers
better performance on large projects, reduced response time after code changes,
more robust change detection, and a reduction in power usage. Django supports
``pywatchman`` 1.2.0 and higher.
.. admonition:: Large directories with many files may cause performance issues
When using Watchman with a project that includes large non-Python
directories like ``node_modules``, it's advisable to ignore this directory
for optimal performance. See the `watchman documentation`_ for information
on how to do this.
.. admonition:: Watchman timeout
The default timeout of ``Watchman`` client is 5 seconds. You can change it
by setting the ``DJANGO_WATCHMAN_TIMEOUT`` environment variable.
.. _Watchman: https://facebook.github.io/watchman/
.. _pywatchman: https://pypi.org/project/pywatchman/
.. _watchman documentation: https://facebook.github.io/watchman/docs/config.html#ignore_dirs
When you start the server, and each time you change Python code while the
server is running, the system check framework will check your entire Django
project for some common errors (see the :djadmin:`check` command). If any
errors are found, they will be printed to standard output.
You can run as many concurrent servers as you want, as long as they're on
separate ports by executing ``django-admin runserver`` more than once.
Note that the default IP address, ``127.0.0.1``, is not accessible from other
machines on your network. To make your development server viewable to other
machines on the network, use its own IP address (e.g. ``192.168.2.1``) or
``0.0.0.0`` or ``::`` (with IPv6 enabled).
You can provide an IPv6 address surrounded by brackets
(e.g. ``[200a::1]:8000``). This will automatically enable IPv6 support.
A hostname containing ASCII-only characters can also be used.
If the :doc:`staticfiles</ref/contrib/staticfiles>` contrib app is enabled
(default in new projects) the :djadmin:`runserver` command will be overridden
with its own :ref:`runserver<staticfiles-runserver>` command.
Logging of each request and response of the server is sent to the
:ref:`django-server-logger` logger.
.. django-admin-option:: --noreload
Disables the auto-reloader. This means any Python code changes you make while
the server is running will *not* take effect if the particular Python modules
have already been loaded into memory.
.. django-admin-option:: --nothreading
Disables use of threading in the development server. The server is
multithreaded by default.
.. django-admin-option:: --ipv6, -6
Uses IPv6 for the development server. This changes the default IP address from
``127.0.0.1`` to ``::1``.
Examples of using different ports and addresses
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Port 8000 on IP address ``127.0.0.1``::
django-admin runserver
Port 8000 on IP address ``1.2.3.4``::
django-admin runserver 1.2.3.4:8000
Port 7000 on IP address ``127.0.0.1``::
django-admin runserver 7000
Port 7000 on IP address ``1.2.3.4``::
django-admin runserver 1.2.3.4:7000
Port 8000 on IPv6 address ``::1``::
django-admin runserver -6
Port 7000 on IPv6 address ``::1``::
django-admin runserver -6 7000
Port 7000 on IPv6 address ``2001:0db8:1234:5678::9``::
django-admin runserver [2001:0db8:1234:5678::9]:7000
Port 8000 on IPv4 address of host ``localhost``::
django-admin runserver localhost:8000