forked from django/django
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.txt
3688 lines (2483 loc) · 111 KB
/
settings.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
========
Settings
========
.. contents::
:local:
:depth: 1
.. warning::
Be careful when you override settings, especially when the default value
is a non-empty list or dictionary, such as :setting:`STATICFILES_FINDERS`.
Make sure you keep the components required by the features of Django you
wish to use.
Core Settings
=============
Here's a list of settings available in Django core and their default values.
Settings provided by contrib apps are listed below, followed by a topical index
of the core settings. For introductory material, see the :doc:`settings topic
guide </topics/settings>`.
.. setting:: ABSOLUTE_URL_OVERRIDES
``ABSOLUTE_URL_OVERRIDES``
--------------------------
Default: ``{}`` (Empty dictionary)
A dictionary mapping ``"app_label.model_name"`` strings to functions that take
a model object and return its URL. This is a way of inserting or overriding
``get_absolute_url()`` methods on a per-installation basis. Example::
ABSOLUTE_URL_OVERRIDES = {
'blogs.weblog': lambda o: "/blogs/%s/" % o.slug,
'news.story': lambda o: "/stories/%s/%s/" % (o.pub_year, o.slug),
}
The model name used in this setting should be all lowercase, regardless of the
case of the actual model class name.
.. setting:: ADMINS
``ADMINS``
----------
Default: ``[]`` (Empty list)
A list of all the people who get code error notifications. When
:setting:`DEBUG=False <DEBUG>` and :class:`~django.utils.log.AdminEmailHandler`
is configured in :setting:`LOGGING` (done by default), Django emails these
people the details of exceptions raised in the request/response cycle.
Each item in the list should be a tuple of (Full name, email address). Example::
[('John', '[email protected]'), ('Mary', '[email protected]')]
.. setting:: ALLOWED_HOSTS
``ALLOWED_HOSTS``
-----------------
Default: ``[]`` (Empty list)
A list of strings representing the host/domain names that this Django site can
serve. This is a security measure to prevent :ref:`HTTP Host header attacks
<host-headers-virtual-hosting>`, which are possible even under many
seemingly-safe web server configurations.
Values in this list can be fully qualified names (e.g. ``'www.example.com'``),
in which case they will be matched against the request's ``Host`` header
exactly (case-insensitive, not including port). A value beginning with a period
can be used as a subdomain wildcard: ``'.example.com'`` will match
``example.com``, ``www.example.com``, and any other subdomain of
``example.com``. A value of ``'*'`` will match anything; in this case you are
responsible to provide your own validation of the ``Host`` header (perhaps in a
middleware; if so this middleware must be listed first in
:setting:`MIDDLEWARE`).
Django also allows the `fully qualified domain name (FQDN)`_ of any entries.
Some browsers include a trailing dot in the ``Host`` header which Django
strips when performing host validation.
.. _`fully qualified domain name (FQDN)`: https://en.wikipedia.org/wiki/Fully_qualified_domain_name
If the ``Host`` header (or ``X-Forwarded-Host`` if
:setting:`USE_X_FORWARDED_HOST` is enabled) does not match any value in this
list, the :meth:`django.http.HttpRequest.get_host()` method will raise
:exc:`~django.core.exceptions.SuspiciousOperation`.
When :setting:`DEBUG` is ``True`` and ``ALLOWED_HOSTS`` is empty, the host
is validated against ``['.localhost', '127.0.0.1', '[::1]']``.
``ALLOWED_HOSTS`` is also :ref:`checked when running tests
<topics-testing-advanced-multiple-hosts>`.
This validation only applies via :meth:`~django.http.HttpRequest.get_host()`;
if your code accesses the ``Host`` header directly from ``request.META`` you
are bypassing this security protection.
.. versionchanged:: 3.1
If ``ALLOWED_HOSTS`` is empty and ``DEBUG=True``, subdomains of localhost
were allowed.
.. setting:: APPEND_SLASH
``APPEND_SLASH``
----------------
Default: ``True``
When set to ``True``, if the request URL does not match any of the patterns
in the URLconf and it doesn't end in a slash, an HTTP redirect is issued to the
same URL with a slash appended. Note that the redirect may cause any data
submitted in a POST request to be lost.
The :setting:`APPEND_SLASH` setting is only used if
:class:`~django.middleware.common.CommonMiddleware` is installed
(see :doc:`/topics/http/middleware`). See also :setting:`PREPEND_WWW`.
.. setting:: CACHES
``CACHES``
----------
Default::
{
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
A dictionary containing the settings for all caches to be used with
Django. It is a nested dictionary whose contents maps cache aliases
to a dictionary containing the options for an individual cache.
The :setting:`CACHES` setting must configure a ``default`` cache;
any number of additional caches may also be specified. If you
are using a cache backend other than the local memory cache, or
you need to define multiple caches, other options will be required.
The following cache options are available.
.. setting:: CACHES-BACKEND
``BACKEND``
~~~~~~~~~~~
Default: ``''`` (Empty string)
The cache backend to use. The built-in cache backends are:
* ``'django.core.cache.backends.db.DatabaseCache'``
* ``'django.core.cache.backends.dummy.DummyCache'``
* ``'django.core.cache.backends.filebased.FileBasedCache'``
* ``'django.core.cache.backends.locmem.LocMemCache'``
* ``'django.core.cache.backends.memcached.MemcachedCache'``
* ``'django.core.cache.backends.memcached.PyLibMCCache'``
You can use a cache backend that doesn't ship with Django by setting
:setting:`BACKEND <CACHES-BACKEND>` to a fully-qualified path of a cache
backend class (i.e. ``mypackage.backends.whatever.WhateverCache``).
.. setting:: CACHES-KEY_FUNCTION
``KEY_FUNCTION``
~~~~~~~~~~~~~~~~
A string containing a dotted path to a function (or any callable) that defines how to
compose a prefix, version and key into a final cache key. The default
implementation is equivalent to the function::
def make_key(key, key_prefix, version):
return ':'.join([key_prefix, str(version), key])
You may use any key function you want, as long as it has the same
argument signature.
See the :ref:`cache documentation <cache_key_transformation>` for more
information.
.. setting:: CACHES-KEY_PREFIX
``KEY_PREFIX``
~~~~~~~~~~~~~~
Default: ``''`` (Empty string)
A string that will be automatically included (prepended by default) to
all cache keys used by the Django server.
See the :ref:`cache documentation <cache_key_prefixing>` for more information.
.. setting:: CACHES-LOCATION
``LOCATION``
~~~~~~~~~~~~
Default: ``''`` (Empty string)
The location of the cache to use. This might be the directory for a
file system cache, a host and port for a memcache server, or an identifying
name for a local memory cache. e.g.::
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
.. setting:: CACHES-OPTIONS
``OPTIONS``
~~~~~~~~~~~
Default: ``None``
Extra parameters to pass to the cache backend. Available parameters
vary depending on your cache backend.
Some information on available parameters can be found in the
:ref:`cache arguments <cache_arguments>` documentation. For more information,
consult your backend module's own documentation.
.. setting:: CACHES-TIMEOUT
``TIMEOUT``
~~~~~~~~~~~
Default: ``300``
The number of seconds before a cache entry is considered stale. If the value of
this settings is ``None``, cache entries will not expire.
.. setting:: CACHES-VERSION
``VERSION``
~~~~~~~~~~~
Default: ``1``
The default version number for cache keys generated by the Django server.
See the :ref:`cache documentation <cache_versioning>` for more information.
.. setting:: CACHE_MIDDLEWARE_ALIAS
``CACHE_MIDDLEWARE_ALIAS``
--------------------------
Default: ``default``
The cache connection to use for the :ref:`cache middleware
<the-per-site-cache>`.
.. setting:: CACHE_MIDDLEWARE_KEY_PREFIX
``CACHE_MIDDLEWARE_KEY_PREFIX``
-------------------------------
Default: ``''`` (Empty string)
A string which will be prefixed to the cache keys generated by the :ref:`cache
middleware <the-per-site-cache>`. This prefix is combined with the
:setting:`KEY_PREFIX <CACHES-KEY_PREFIX>` setting; it does not replace it.
See :doc:`/topics/cache`.
.. setting:: CACHE_MIDDLEWARE_SECONDS
``CACHE_MIDDLEWARE_SECONDS``
----------------------------
Default: ``600``
The default number of seconds to cache a page for the :ref:`cache middleware
<the-per-site-cache>`.
See :doc:`/topics/cache`.
.. _settings-csrf:
.. setting:: CSRF_COOKIE_AGE
``CSRF_COOKIE_AGE``
-------------------
Default: ``31449600`` (approximately 1 year, in seconds)
The age of CSRF cookies, in seconds.
The reason for setting a long-lived expiration time is to avoid problems in
the case of a user closing a browser or bookmarking a page and then loading
that page from a browser cache. Without persistent cookies, the form submission
would fail in this case.
Some browsers (specifically Internet Explorer) can disallow the use of
persistent cookies or can have the indexes to the cookie jar corrupted on disk,
thereby causing CSRF protection checks to (sometimes intermittently) fail.
Change this setting to ``None`` to use session-based CSRF cookies, which
keep the cookies in-memory instead of on persistent storage.
.. setting:: CSRF_COOKIE_DOMAIN
``CSRF_COOKIE_DOMAIN``
----------------------
Default: ``None``
The domain to be used when setting the CSRF cookie. This can be useful for
easily allowing cross-subdomain requests to be excluded from the normal cross
site request forgery protection. It should be set to a string such as
``"example.com"`` to allow a POST request from a form on one subdomain to be
accepted by a view served from another subdomain.
Please note that the presence of this setting does not imply that Django's CSRF
protection is safe from cross-subdomain attacks by default - please see the
:ref:`CSRF limitations <csrf-limitations>` section.
.. setting:: CSRF_COOKIE_HTTPONLY
``CSRF_COOKIE_HTTPONLY``
------------------------
Default: ``False``
Whether to use ``HttpOnly`` flag on the CSRF cookie. If this is set to
``True``, client-side JavaScript will not be able to access the CSRF cookie.
Designating the CSRF cookie as ``HttpOnly`` doesn't offer any practical
protection because CSRF is only to protect against cross-domain attacks. If an
attacker can read the cookie via JavaScript, they're already on the same domain
as far as the browser knows, so they can do anything they like anyway. (XSS is
a much bigger hole than CSRF.)
Although the setting offers little practical benefit, it's sometimes required
by security auditors.
If you enable this and need to send the value of the CSRF token with an AJAX
request, your JavaScript must pull the value :ref:`from a hidden CSRF token
form input <acquiring-csrf-token-from-html>` instead of :ref:`from the cookie
<acquiring-csrf-token-from-cookie>`.
See :setting:`SESSION_COOKIE_HTTPONLY` for details on ``HttpOnly``.
.. setting:: CSRF_COOKIE_NAME
``CSRF_COOKIE_NAME``
--------------------
Default: ``'csrftoken'``
The name of the cookie to use for the CSRF authentication token. This can be
whatever you want (as long as it's different from the other cookie names in
your application). See :doc:`/ref/csrf`.
.. setting:: CSRF_COOKIE_PATH
``CSRF_COOKIE_PATH``
--------------------
Default: ``'/'``
The path set on the CSRF cookie. This should either match the URL path of your
Django installation or be a parent of that path.
This is useful if you have multiple Django instances running under the same
hostname. They can use different cookie paths, and each instance will only see
its own CSRF cookie.
.. setting:: CSRF_COOKIE_SAMESITE
``CSRF_COOKIE_SAMESITE``
------------------------
Default: ``'Lax'``
The value of the `SameSite`_ flag on the CSRF cookie. This flag prevents the
cookie from being sent in cross-site requests.
See :setting:`SESSION_COOKIE_SAMESITE` for details about ``SameSite``.
.. versionchanged:: 3.1
Setting ``CSRF_COOKIE_SAMESITE = 'None'`` was allowed.
.. setting:: CSRF_COOKIE_SECURE
``CSRF_COOKIE_SECURE``
----------------------
Default: ``False``
Whether to use a secure cookie for the CSRF cookie. If this is set to ``True``,
the cookie will be marked as "secure", which means browsers may ensure that the
cookie is only sent with an HTTPS connection.
.. setting:: CSRF_USE_SESSIONS
``CSRF_USE_SESSIONS``
---------------------
Default: ``False``
Whether to store the CSRF token in the user's session instead of in a cookie.
It requires the use of :mod:`django.contrib.sessions`.
Storing the CSRF token in a cookie (Django's default) is safe, but storing it
in the session is common practice in other web frameworks and therefore
sometimes demanded by security auditors.
Since the :ref:`default error views <error-views>` require the CSRF token,
:class:`~django.contrib.sessions.middleware.SessionMiddleware` must appear in
:setting:`MIDDLEWARE` before any middleware that may raise an exception to
trigger an error view (such as :exc:`~django.core.exceptions.PermissionDenied`)
if you're using ``CSRF_USE_SESSIONS``. See :ref:`middleware-ordering`.
.. setting:: CSRF_FAILURE_VIEW
``CSRF_FAILURE_VIEW``
---------------------
Default: ``'django.views.csrf.csrf_failure'``
A dotted path to the view function to be used when an incoming request is
rejected by the :doc:`CSRF protection </ref/csrf>`. The function should have
this signature::
def csrf_failure(request, reason=""):
...
where ``reason`` is a short message (intended for developers or logging, not
for end users) indicating the reason the request was rejected. It should return
an :class:`~django.http.HttpResponseForbidden`.
``django.views.csrf.csrf_failure()`` accepts an additional ``template_name``
parameter that defaults to ``'403_csrf.html'``. If a template with that name
exists, it will be used to render the page.
.. setting:: CSRF_HEADER_NAME
``CSRF_HEADER_NAME``
--------------------
Default: ``'HTTP_X_CSRFTOKEN'``
The name of the request header used for CSRF authentication.
As with other HTTP headers in ``request.META``, the header name received from
the server is normalized by converting all characters to uppercase, replacing
any hyphens with underscores, and adding an ``'HTTP_'`` prefix to the name.
For example, if your client sends a ``'X-XSRF-TOKEN'`` header, the setting
should be ``'HTTP_X_XSRF_TOKEN'``.
.. setting:: CSRF_TRUSTED_ORIGINS
``CSRF_TRUSTED_ORIGINS``
------------------------
Default: ``[]`` (Empty list)
A list of hosts which are trusted origins for unsafe requests (e.g. ``POST``).
For a :meth:`secure <django.http.HttpRequest.is_secure>` unsafe
request, Django's CSRF protection requires that the request have a ``Referer``
header that matches the origin present in the ``Host`` header. This prevents,
for example, a ``POST`` request from ``subdomain.example.com`` from succeeding
against ``api.example.com``. If you need cross-origin unsafe requests over
HTTPS, continuing the example, add ``"subdomain.example.com"`` to this list.
The setting also supports subdomains, so you could add ``".example.com"``, for
example, to allow access from all subdomains of ``example.com``.
.. setting:: DATABASES
``DATABASES``
-------------
Default: ``{}`` (Empty dictionary)
A dictionary containing the settings for all databases to be used with
Django. It is a nested dictionary whose contents map a database alias
to a dictionary containing the options for an individual database.
The :setting:`DATABASES` setting must configure a ``default`` database;
any number of additional databases may also be specified.
The simplest possible settings file is for a single-database setup using
SQLite. This can be configured using the following::
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase',
}
}
When connecting to other database backends, such as MariaDB, MySQL, Oracle, or
PostgreSQL, additional connection parameters will be required. See
the :setting:`ENGINE <DATABASE-ENGINE>` setting below on how to specify
other database types. This example is for PostgreSQL::
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
The following inner options that may be required for more complex
configurations are available:
.. setting:: DATABASE-ATOMIC_REQUESTS
``ATOMIC_REQUESTS``
~~~~~~~~~~~~~~~~~~~
Default: ``False``
Set this to ``True`` to wrap each view in a transaction on this database. See
:ref:`tying-transactions-to-http-requests`.
.. setting:: DATABASE-AUTOCOMMIT
``AUTOCOMMIT``
~~~~~~~~~~~~~~
Default: ``True``
Set this to ``False`` if you want to :ref:`disable Django's transaction
management <deactivate-transaction-management>` and implement your own.
.. setting:: DATABASE-ENGINE
``ENGINE``
~~~~~~~~~~
Default: ``''`` (Empty string)
The database backend to use. The built-in database backends are:
* ``'django.db.backends.postgresql'``
* ``'django.db.backends.mysql'``
* ``'django.db.backends.sqlite3'``
* ``'django.db.backends.oracle'``
You can use a database backend that doesn't ship with Django by setting
``ENGINE`` to a fully-qualified path (i.e. ``mypackage.backends.whatever``).
.. setting:: HOST
``HOST``
~~~~~~~~
Default: ``''`` (Empty string)
Which host to use when connecting to the database. An empty string means
localhost. Not used with SQLite.
If this value starts with a forward slash (``'/'``) and you're using MySQL,
MySQL will connect via a Unix socket to the specified socket. For example::
"HOST": '/var/run/mysql'
If you're using MySQL and this value *doesn't* start with a forward slash, then
this value is assumed to be the host.
If you're using PostgreSQL, by default (empty :setting:`HOST`), the connection
to the database is done through UNIX domain sockets ('local' lines in
``pg_hba.conf``). If your UNIX domain socket is not in the standard location,
use the same value of ``unix_socket_directory`` from ``postgresql.conf``.
If you want to connect through TCP sockets, set :setting:`HOST` to 'localhost'
or '127.0.0.1' ('host' lines in ``pg_hba.conf``).
On Windows, you should always define :setting:`HOST`, as UNIX domain sockets
are not available.
.. setting:: NAME
``NAME``
~~~~~~~~
Default: ``''`` (Empty string)
The name of the database to use. For SQLite, it's the full path to the database
file. When specifying the path, always use forward slashes, even on Windows
(e.g. ``C:/homes/user/mysite/sqlite3.db``).
.. setting:: CONN_MAX_AGE
``CONN_MAX_AGE``
~~~~~~~~~~~~~~~~
Default: ``0``
The lifetime of a database connection, as an integer of seconds. Use ``0`` to
close database connections at the end of each request — Django's historical
behavior — and ``None`` for unlimited persistent connections.
.. setting:: OPTIONS
``OPTIONS``
~~~~~~~~~~~
Default: ``{}`` (Empty dictionary)
Extra parameters to use when connecting to the database. Available parameters
vary depending on your database backend.
Some information on available parameters can be found in the
:doc:`Database Backends </ref/databases>` documentation. For more information,
consult your backend module's own documentation.
.. setting:: PASSWORD
``PASSWORD``
~~~~~~~~~~~~
Default: ``''`` (Empty string)
The password to use when connecting to the database. Not used with SQLite.
.. setting:: PORT
``PORT``
~~~~~~~~
Default: ``''`` (Empty string)
The port to use when connecting to the database. An empty string means the
default port. Not used with SQLite.
.. setting:: DATABASE-TIME_ZONE
``TIME_ZONE``
~~~~~~~~~~~~~
Default: ``None``
A string representing the time zone for this database connection or ``None``.
This inner option of the :setting:`DATABASES` setting accepts the same values
as the general :setting:`TIME_ZONE` setting.
When :setting:`USE_TZ` is ``True`` and this option is set, reading datetimes
from the database returns aware datetimes in this time zone instead of UTC.
When :setting:`USE_TZ` is ``False``, it is an error to set this option.
* If the database backend doesn't support time zones (e.g. SQLite, MySQL,
Oracle), Django reads and writes datetimes in local time according to this
option if it is set and in UTC if it isn't.
Changing the connection time zone changes how datetimes are read from and
written to the database.
* If Django manages the database and you don't have a strong reason to do
otherwise, you should leave this option unset. It's best to store datetimes
in UTC because it avoids ambiguous or nonexistent datetimes during daylight
saving time changes. Also, receiving datetimes in UTC keeps datetime
arithmetic simple — there's no need for the ``normalize()`` method provided
by pytz.
* If you're connecting to a third-party database that stores datetimes in a
local time rather than UTC, then you must set this option to the
appropriate time zone. Likewise, if Django manages the database but
third-party systems connect to the same database and expect to find
datetimes in local time, then you must set this option.
* If the database backend supports time zones (e.g. PostgreSQL), the
``TIME_ZONE`` option is very rarely needed. It can be changed at any time;
the database takes care of converting datetimes to the desired time zone.
Setting the time zone of the database connection may be useful for running
raw SQL queries involving date/time functions provided by the database, such
as ``date_trunc``, because their results depend on the time zone.
However, this has a downside: receiving all datetimes in local time makes
datetime arithmetic more tricky — you must call the ``normalize()`` method
provided by pytz after each operation.
Consider converting to local time explicitly with ``AT TIME ZONE`` in raw SQL
queries instead of setting the ``TIME_ZONE`` option.
.. versionchanged:: 3.1
Using this option when the database backend supports time zones was allowed.
.. setting:: DATABASE-DISABLE_SERVER_SIDE_CURSORS
``DISABLE_SERVER_SIDE_CURSORS``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Default: ``False``
Set this to ``True`` if you want to disable the use of server-side cursors with
:meth:`.QuerySet.iterator`. :ref:`transaction-pooling-server-side-cursors`
describes the use case.
This is a PostgreSQL-specific setting.
.. setting:: USER
``USER``
~~~~~~~~
Default: ``''`` (Empty string)
The username to use when connecting to the database. Not used with SQLite.
.. setting:: DATABASE-TEST
``TEST``
~~~~~~~~
Default: ``{}`` (Empty dictionary)
A dictionary of settings for test databases; for more details about the
creation and use of test databases, see :ref:`the-test-database`.
Here's an example with a test database configuration::
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'USER': 'mydatabaseuser',
'NAME': 'mydatabase',
'TEST': {
'NAME': 'mytestdatabase',
},
},
}
The following keys in the ``TEST`` dictionary are available:
.. setting:: TEST_CHARSET
``CHARSET``
^^^^^^^^^^^
Default: ``None``
The character set encoding used to create the test database. The value of this
string is passed directly through to the database, so its format is
backend-specific.
Supported by the PostgreSQL_ (``postgresql``) and MySQL_ (``mysql``) backends.
.. _PostgreSQL: https://www.postgresql.org/docs/current/multibyte.html
.. _MySQL: https://dev.mysql.com/doc/refman/en/charset-charsets.html
.. setting:: TEST_COLLATION
``COLLATION``
^^^^^^^^^^^^^
Default: ``None``
The collation order to use when creating the test database. This value is
passed directly to the backend, so its format is backend-specific.
Only supported for the ``mysql`` backend (see the `MySQL manual`_ for details).
.. _MySQL manual: MySQL_
.. setting:: TEST_DEPENDENCIES
``DEPENDENCIES``
^^^^^^^^^^^^^^^^
Default: ``['default']``, for all databases other than ``default``,
which has no dependencies.
The creation-order dependencies of the database. See the documentation
on :ref:`controlling the creation order of test databases
<topics-testing-creation-dependencies>` for details.
.. setting:: TEST_MIGRATE
``MIGRATE``
^^^^^^^^^^^
.. versionadded:: 3.1
Default: ``True``
When set to ``False``, migrations won't run when creating the test database.
.. setting:: TEST_MIRROR
``MIRROR``
^^^^^^^^^^
Default: ``None``
The alias of the database that this database should mirror during
testing.
This setting exists to allow for testing of primary/replica
(referred to as master/slave by some databases)
configurations of multiple databases. See the documentation on
:ref:`testing primary/replica configurations
<topics-testing-primaryreplica>` for details.
.. setting:: TEST_NAME
``NAME``
^^^^^^^^
Default: ``None``
The name of database to use when running the test suite.
If the default value (``None``) is used with the SQLite database engine, the
tests will use a memory resident database. For all other database engines the
test database will use the name ``'test_' + DATABASE_NAME``.
See :ref:`the-test-database`.
.. setting:: TEST_SERIALIZE
``SERIALIZE``
^^^^^^^^^^^^^
Boolean value to control whether or not the default test runner serializes the
database into an in-memory JSON string before running tests (used to restore
the database state between tests if you don't have transactions). You can set
this to ``False`` to speed up creation time if you don't have any test classes
with :ref:`serialized_rollback=True <test-case-serialized-rollback>`.
.. setting:: TEST_TEMPLATE
``TEMPLATE``
^^^^^^^^^^^^
This is a PostgreSQL-specific setting.
The name of a `template`_ (e.g. ``'template0'``) from which to create the test
database.
.. _template: https://www.postgresql.org/docs/current/sql-createdatabase.html
.. setting:: TEST_CREATE
``CREATE_DB``
^^^^^^^^^^^^^
Default: ``True``
This is an Oracle-specific setting.
If it is set to ``False``, the test tablespaces won't be automatically created
at the beginning of the tests or dropped at the end.
.. setting:: TEST_USER_CREATE
``CREATE_USER``
^^^^^^^^^^^^^^^
Default: ``True``
This is an Oracle-specific setting.
If it is set to ``False``, the test user won't be automatically created at the
beginning of the tests and dropped at the end.
.. setting:: TEST_USER
``USER``
^^^^^^^^
Default: ``None``
This is an Oracle-specific setting.
The username to use when connecting to the Oracle database that will be used
when running tests. If not provided, Django will use ``'test_' + USER``.
.. setting:: TEST_PASSWD
``PASSWORD``
^^^^^^^^^^^^
Default: ``None``
This is an Oracle-specific setting.
The password to use when connecting to the Oracle database that will be used
when running tests. If not provided, Django will generate a random password.
.. setting:: TEST_ORACLE_MANAGED_FILES
``ORACLE_MANAGED_FILES``
^^^^^^^^^^^^^^^^^^^^^^^^
Default: ``False``
This is an Oracle-specific setting.
If set to ``True``, Oracle Managed Files (OMF) tablespaces will be used.
:setting:`DATAFILE` and :setting:`DATAFILE_TMP` will be ignored.
.. setting:: TEST_TBLSPACE
``TBLSPACE``
^^^^^^^^^^^^
Default: ``None``
This is an Oracle-specific setting.
The name of the tablespace that will be used when running tests. If not
provided, Django will use ``'test_' + USER``.
.. setting:: TEST_TBLSPACE_TMP
``TBLSPACE_TMP``
^^^^^^^^^^^^^^^^
Default: ``None``
This is an Oracle-specific setting.
The name of the temporary tablespace that will be used when running tests. If
not provided, Django will use ``'test_' + USER + '_temp'``.
.. setting:: DATAFILE
``DATAFILE``
^^^^^^^^^^^^
Default: ``None``
This is an Oracle-specific setting.
The name of the datafile to use for the TBLSPACE. If not provided, Django will
use ``TBLSPACE + '.dbf'``.
.. setting:: DATAFILE_TMP
``DATAFILE_TMP``
^^^^^^^^^^^^^^^^
Default: ``None``
This is an Oracle-specific setting.
The name of the datafile to use for the TBLSPACE_TMP. If not provided, Django
will use ``TBLSPACE_TMP + '.dbf'``.
.. setting:: DATAFILE_MAXSIZE
``DATAFILE_MAXSIZE``
^^^^^^^^^^^^^^^^^^^^
Default: ``'500M'``
This is an Oracle-specific setting.
The maximum size that the DATAFILE is allowed to grow to.
.. setting:: DATAFILE_TMP_MAXSIZE
``DATAFILE_TMP_MAXSIZE``
^^^^^^^^^^^^^^^^^^^^^^^^
Default: ``'500M'``
This is an Oracle-specific setting.
The maximum size that the DATAFILE_TMP is allowed to grow to.
.. setting:: DATAFILE_SIZE
``DATAFILE_SIZE``
^^^^^^^^^^^^^^^^^
Default: ``'50M'``
This is an Oracle-specific setting.
The initial size of the DATAFILE.
.. setting:: DATAFILE_TMP_SIZE
``DATAFILE_TMP_SIZE``
^^^^^^^^^^^^^^^^^^^^^
Default: ``'50M'``
This is an Oracle-specific setting.
The initial size of the DATAFILE_TMP.
.. setting:: DATAFILE_EXTSIZE
``DATAFILE_EXTSIZE``
^^^^^^^^^^^^^^^^^^^^