settings.txt 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689
  1. ========
  2. Settings
  3. ========
  4. .. contents::
  5. :local:
  6. :depth: 1
  7. .. warning::
  8. Be careful when you override settings, especially when the default value
  9. is a non-empty list or dictionary, such as :setting:`STATICFILES_FINDERS`.
  10. Make sure you keep the components required by the features of Django you
  11. wish to use.
  12. Core Settings
  13. =============
  14. Here's a list of settings available in Django core and their default values.
  15. Settings provided by contrib apps are listed below, followed by a topical index
  16. of the core settings. For introductory material, see the :doc:`settings topic
  17. guide </topics/settings>`.
  18. .. setting:: ABSOLUTE_URL_OVERRIDES
  19. ``ABSOLUTE_URL_OVERRIDES``
  20. --------------------------
  21. Default: ``{}`` (Empty dictionary)
  22. A dictionary mapping ``"app_label.model_name"`` strings to functions that take
  23. a model object and return its URL. This is a way of inserting or overriding
  24. ``get_absolute_url()`` methods on a per-installation basis. Example::
  25. ABSOLUTE_URL_OVERRIDES = {
  26. 'blogs.weblog': lambda o: "/blogs/%s/" % o.slug,
  27. 'news.story': lambda o: "/stories/%s/%s/" % (o.pub_year, o.slug),
  28. }
  29. The model name used in this setting should be all lowercase, regardless of the
  30. case of the actual model class name.
  31. .. setting:: ADMINS
  32. ``ADMINS``
  33. ----------
  34. Default: ``[]`` (Empty list)
  35. A list of all the people who get code error notifications. When
  36. :setting:`DEBUG=False <DEBUG>` and :class:`~django.utils.log.AdminEmailHandler`
  37. is configured in :setting:`LOGGING` (done by default), Django emails these
  38. people the details of exceptions raised in the request/response cycle.
  39. Each item in the list should be a tuple of (Full name, email address). Example::
  40. [('John', 'john@example.com'), ('Mary', 'mary@example.com')]
  41. .. setting:: ALLOWED_HOSTS
  42. ``ALLOWED_HOSTS``
  43. -----------------
  44. Default: ``[]`` (Empty list)
  45. A list of strings representing the host/domain names that this Django site can
  46. serve. This is a security measure to prevent :ref:`HTTP Host header attacks
  47. <host-headers-virtual-hosting>`, which are possible even under many
  48. seemingly-safe web server configurations.
  49. Values in this list can be fully qualified names (e.g. ``'www.example.com'``),
  50. in which case they will be matched against the request's ``Host`` header
  51. exactly (case-insensitive, not including port). A value beginning with a period
  52. can be used as a subdomain wildcard: ``'.example.com'`` will match
  53. ``example.com``, ``www.example.com``, and any other subdomain of
  54. ``example.com``. A value of ``'*'`` will match anything; in this case you are
  55. responsible to provide your own validation of the ``Host`` header (perhaps in a
  56. middleware; if so this middleware must be listed first in
  57. :setting:`MIDDLEWARE`).
  58. Django also allows the `fully qualified domain name (FQDN)`_ of any entries.
  59. Some browsers include a trailing dot in the ``Host`` header which Django
  60. strips when performing host validation.
  61. .. _`fully qualified domain name (FQDN)`: https://en.wikipedia.org/wiki/Fully_qualified_domain_name
  62. If the ``Host`` header (or ``X-Forwarded-Host`` if
  63. :setting:`USE_X_FORWARDED_HOST` is enabled) does not match any value in this
  64. list, the :meth:`django.http.HttpRequest.get_host()` method will raise
  65. :exc:`~django.core.exceptions.SuspiciousOperation`.
  66. When :setting:`DEBUG` is ``True`` and ``ALLOWED_HOSTS`` is empty, the host
  67. is validated against ``['.localhost', '127.0.0.1', '[::1]']``.
  68. ``ALLOWED_HOSTS`` is also :ref:`checked when running tests
  69. <topics-testing-advanced-multiple-hosts>`.
  70. This validation only applies via :meth:`~django.http.HttpRequest.get_host()`;
  71. if your code accesses the ``Host`` header directly from ``request.META`` you
  72. are bypassing this security protection.
  73. .. versionchanged:: 3.1
  74. If ``ALLOWED_HOSTS`` is empty and ``DEBUG=True``, subdomains of localhost
  75. were allowed.
  76. .. setting:: APPEND_SLASH
  77. ``APPEND_SLASH``
  78. ----------------
  79. Default: ``True``
  80. When set to ``True``, if the request URL does not match any of the patterns
  81. in the URLconf and it doesn't end in a slash, an HTTP redirect is issued to the
  82. same URL with a slash appended. Note that the redirect may cause any data
  83. submitted in a POST request to be lost.
  84. The :setting:`APPEND_SLASH` setting is only used if
  85. :class:`~django.middleware.common.CommonMiddleware` is installed
  86. (see :doc:`/topics/http/middleware`). See also :setting:`PREPEND_WWW`.
  87. .. setting:: CACHES
  88. ``CACHES``
  89. ----------
  90. Default::
  91. {
  92. 'default': {
  93. 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
  94. }
  95. }
  96. A dictionary containing the settings for all caches to be used with
  97. Django. It is a nested dictionary whose contents maps cache aliases
  98. to a dictionary containing the options for an individual cache.
  99. The :setting:`CACHES` setting must configure a ``default`` cache;
  100. any number of additional caches may also be specified. If you
  101. are using a cache backend other than the local memory cache, or
  102. you need to define multiple caches, other options will be required.
  103. The following cache options are available.
  104. .. setting:: CACHES-BACKEND
  105. ``BACKEND``
  106. ~~~~~~~~~~~
  107. Default: ``''`` (Empty string)
  108. The cache backend to use. The built-in cache backends are:
  109. * ``'django.core.cache.backends.db.DatabaseCache'``
  110. * ``'django.core.cache.backends.dummy.DummyCache'``
  111. * ``'django.core.cache.backends.filebased.FileBasedCache'``
  112. * ``'django.core.cache.backends.locmem.LocMemCache'``
  113. * ``'django.core.cache.backends.memcached.MemcachedCache'``
  114. * ``'django.core.cache.backends.memcached.PyLibMCCache'``
  115. You can use a cache backend that doesn't ship with Django by setting
  116. :setting:`BACKEND <CACHES-BACKEND>` to a fully-qualified path of a cache
  117. backend class (i.e. ``mypackage.backends.whatever.WhateverCache``).
  118. .. setting:: CACHES-KEY_FUNCTION
  119. ``KEY_FUNCTION``
  120. ~~~~~~~~~~~~~~~~
  121. A string containing a dotted path to a function (or any callable) that defines how to
  122. compose a prefix, version and key into a final cache key. The default
  123. implementation is equivalent to the function::
  124. def make_key(key, key_prefix, version):
  125. return ':'.join([key_prefix, str(version), key])
  126. You may use any key function you want, as long as it has the same
  127. argument signature.
  128. See the :ref:`cache documentation <cache_key_transformation>` for more
  129. information.
  130. .. setting:: CACHES-KEY_PREFIX
  131. ``KEY_PREFIX``
  132. ~~~~~~~~~~~~~~
  133. Default: ``''`` (Empty string)
  134. A string that will be automatically included (prepended by default) to
  135. all cache keys used by the Django server.
  136. See the :ref:`cache documentation <cache_key_prefixing>` for more information.
  137. .. setting:: CACHES-LOCATION
  138. ``LOCATION``
  139. ~~~~~~~~~~~~
  140. Default: ``''`` (Empty string)
  141. The location of the cache to use. This might be the directory for a
  142. file system cache, a host and port for a memcache server, or an identifying
  143. name for a local memory cache. e.g.::
  144. CACHES = {
  145. 'default': {
  146. 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
  147. 'LOCATION': '/var/tmp/django_cache',
  148. }
  149. }
  150. .. setting:: CACHES-OPTIONS
  151. ``OPTIONS``
  152. ~~~~~~~~~~~
  153. Default: ``None``
  154. Extra parameters to pass to the cache backend. Available parameters
  155. vary depending on your cache backend.
  156. Some information on available parameters can be found in the
  157. :ref:`cache arguments <cache_arguments>` documentation. For more information,
  158. consult your backend module's own documentation.
  159. .. setting:: CACHES-TIMEOUT
  160. ``TIMEOUT``
  161. ~~~~~~~~~~~
  162. Default: ``300``
  163. The number of seconds before a cache entry is considered stale. If the value of
  164. this settings is ``None``, cache entries will not expire.
  165. .. setting:: CACHES-VERSION
  166. ``VERSION``
  167. ~~~~~~~~~~~
  168. Default: ``1``
  169. The default version number for cache keys generated by the Django server.
  170. See the :ref:`cache documentation <cache_versioning>` for more information.
  171. .. setting:: CACHE_MIDDLEWARE_ALIAS
  172. ``CACHE_MIDDLEWARE_ALIAS``
  173. --------------------------
  174. Default: ``'default'``
  175. The cache connection to use for the :ref:`cache middleware
  176. <the-per-site-cache>`.
  177. .. setting:: CACHE_MIDDLEWARE_KEY_PREFIX
  178. ``CACHE_MIDDLEWARE_KEY_PREFIX``
  179. -------------------------------
  180. Default: ``''`` (Empty string)
  181. A string which will be prefixed to the cache keys generated by the :ref:`cache
  182. middleware <the-per-site-cache>`. This prefix is combined with the
  183. :setting:`KEY_PREFIX <CACHES-KEY_PREFIX>` setting; it does not replace it.
  184. See :doc:`/topics/cache`.
  185. .. setting:: CACHE_MIDDLEWARE_SECONDS
  186. ``CACHE_MIDDLEWARE_SECONDS``
  187. ----------------------------
  188. Default: ``600``
  189. The default number of seconds to cache a page for the :ref:`cache middleware
  190. <the-per-site-cache>`.
  191. See :doc:`/topics/cache`.
  192. .. _settings-csrf:
  193. .. setting:: CSRF_COOKIE_AGE
  194. ``CSRF_COOKIE_AGE``
  195. -------------------
  196. Default: ``31449600`` (approximately 1 year, in seconds)
  197. The age of CSRF cookies, in seconds.
  198. The reason for setting a long-lived expiration time is to avoid problems in
  199. the case of a user closing a browser or bookmarking a page and then loading
  200. that page from a browser cache. Without persistent cookies, the form submission
  201. would fail in this case.
  202. Some browsers (specifically Internet Explorer) can disallow the use of
  203. persistent cookies or can have the indexes to the cookie jar corrupted on disk,
  204. thereby causing CSRF protection checks to (sometimes intermittently) fail.
  205. Change this setting to ``None`` to use session-based CSRF cookies, which
  206. keep the cookies in-memory instead of on persistent storage.
  207. .. setting:: CSRF_COOKIE_DOMAIN
  208. ``CSRF_COOKIE_DOMAIN``
  209. ----------------------
  210. Default: ``None``
  211. The domain to be used when setting the CSRF cookie. This can be useful for
  212. easily allowing cross-subdomain requests to be excluded from the normal cross
  213. site request forgery protection. It should be set to a string such as
  214. ``"example.com"`` to allow a POST request from a form on one subdomain to be
  215. accepted by a view served from another subdomain.
  216. Please note that the presence of this setting does not imply that Django's CSRF
  217. protection is safe from cross-subdomain attacks by default - please see the
  218. :ref:`CSRF limitations <csrf-limitations>` section.
  219. .. setting:: CSRF_COOKIE_HTTPONLY
  220. ``CSRF_COOKIE_HTTPONLY``
  221. ------------------------
  222. Default: ``False``
  223. Whether to use ``HttpOnly`` flag on the CSRF cookie. If this is set to
  224. ``True``, client-side JavaScript will not be able to access the CSRF cookie.
  225. Designating the CSRF cookie as ``HttpOnly`` doesn't offer any practical
  226. protection because CSRF is only to protect against cross-domain attacks. If an
  227. attacker can read the cookie via JavaScript, they're already on the same domain
  228. as far as the browser knows, so they can do anything they like anyway. (XSS is
  229. a much bigger hole than CSRF.)
  230. Although the setting offers little practical benefit, it's sometimes required
  231. by security auditors.
  232. If you enable this and need to send the value of the CSRF token with an AJAX
  233. request, your JavaScript must pull the value :ref:`from a hidden CSRF token
  234. form input <acquiring-csrf-token-from-html>` instead of :ref:`from the cookie
  235. <acquiring-csrf-token-from-cookie>`.
  236. See :setting:`SESSION_COOKIE_HTTPONLY` for details on ``HttpOnly``.
  237. .. setting:: CSRF_COOKIE_NAME
  238. ``CSRF_COOKIE_NAME``
  239. --------------------
  240. Default: ``'csrftoken'``
  241. The name of the cookie to use for the CSRF authentication token. This can be
  242. whatever you want (as long as it's different from the other cookie names in
  243. your application). See :doc:`/ref/csrf`.
  244. .. setting:: CSRF_COOKIE_PATH
  245. ``CSRF_COOKIE_PATH``
  246. --------------------
  247. Default: ``'/'``
  248. The path set on the CSRF cookie. This should either match the URL path of your
  249. Django installation or be a parent of that path.
  250. This is useful if you have multiple Django instances running under the same
  251. hostname. They can use different cookie paths, and each instance will only see
  252. its own CSRF cookie.
  253. .. setting:: CSRF_COOKIE_SAMESITE
  254. ``CSRF_COOKIE_SAMESITE``
  255. ------------------------
  256. Default: ``'Lax'``
  257. The value of the `SameSite`_ flag on the CSRF cookie. This flag prevents the
  258. cookie from being sent in cross-site requests.
  259. See :setting:`SESSION_COOKIE_SAMESITE` for details about ``SameSite``.
  260. .. versionchanged:: 3.1
  261. Setting ``CSRF_COOKIE_SAMESITE = 'None'`` was allowed.
  262. .. setting:: CSRF_COOKIE_SECURE
  263. ``CSRF_COOKIE_SECURE``
  264. ----------------------
  265. Default: ``False``
  266. Whether to use a secure cookie for the CSRF cookie. If this is set to ``True``,
  267. the cookie will be marked as "secure", which means browsers may ensure that the
  268. cookie is only sent with an HTTPS connection.
  269. .. setting:: CSRF_USE_SESSIONS
  270. ``CSRF_USE_SESSIONS``
  271. ---------------------
  272. Default: ``False``
  273. Whether to store the CSRF token in the user's session instead of in a cookie.
  274. It requires the use of :mod:`django.contrib.sessions`.
  275. Storing the CSRF token in a cookie (Django's default) is safe, but storing it
  276. in the session is common practice in other web frameworks and therefore
  277. sometimes demanded by security auditors.
  278. Since the :ref:`default error views <error-views>` require the CSRF token,
  279. :class:`~django.contrib.sessions.middleware.SessionMiddleware` must appear in
  280. :setting:`MIDDLEWARE` before any middleware that may raise an exception to
  281. trigger an error view (such as :exc:`~django.core.exceptions.PermissionDenied`)
  282. if you're using ``CSRF_USE_SESSIONS``. See :ref:`middleware-ordering`.
  283. .. setting:: CSRF_FAILURE_VIEW
  284. ``CSRF_FAILURE_VIEW``
  285. ---------------------
  286. Default: ``'django.views.csrf.csrf_failure'``
  287. A dotted path to the view function to be used when an incoming request is
  288. rejected by the :doc:`CSRF protection </ref/csrf>`. The function should have
  289. this signature::
  290. def csrf_failure(request, reason=""):
  291. ...
  292. where ``reason`` is a short message (intended for developers or logging, not
  293. for end users) indicating the reason the request was rejected. It should return
  294. an :class:`~django.http.HttpResponseForbidden`.
  295. ``django.views.csrf.csrf_failure()`` accepts an additional ``template_name``
  296. parameter that defaults to ``'403_csrf.html'``. If a template with that name
  297. exists, it will be used to render the page.
  298. .. setting:: CSRF_HEADER_NAME
  299. ``CSRF_HEADER_NAME``
  300. --------------------
  301. Default: ``'HTTP_X_CSRFTOKEN'``
  302. The name of the request header used for CSRF authentication.
  303. As with other HTTP headers in ``request.META``, the header name received from
  304. the server is normalized by converting all characters to uppercase, replacing
  305. any hyphens with underscores, and adding an ``'HTTP_'`` prefix to the name.
  306. For example, if your client sends a ``'X-XSRF-TOKEN'`` header, the setting
  307. should be ``'HTTP_X_XSRF_TOKEN'``.
  308. .. setting:: CSRF_TRUSTED_ORIGINS
  309. ``CSRF_TRUSTED_ORIGINS``
  310. ------------------------
  311. Default: ``[]`` (Empty list)
  312. A list of hosts which are trusted origins for unsafe requests (e.g. ``POST``).
  313. For a :meth:`secure <django.http.HttpRequest.is_secure>` unsafe
  314. request, Django's CSRF protection requires that the request have a ``Referer``
  315. header that matches the origin present in the ``Host`` header. This prevents,
  316. for example, a ``POST`` request from ``subdomain.example.com`` from succeeding
  317. against ``api.example.com``. If you need cross-origin unsafe requests over
  318. HTTPS, continuing the example, add ``"subdomain.example.com"`` to this list.
  319. The setting also supports subdomains, so you could add ``".example.com"``, for
  320. example, to allow access from all subdomains of ``example.com``.
  321. .. setting:: DATABASES
  322. ``DATABASES``
  323. -------------
  324. Default: ``{}`` (Empty dictionary)
  325. A dictionary containing the settings for all databases to be used with
  326. Django. It is a nested dictionary whose contents map a database alias
  327. to a dictionary containing the options for an individual database.
  328. The :setting:`DATABASES` setting must configure a ``default`` database;
  329. any number of additional databases may also be specified.
  330. The simplest possible settings file is for a single-database setup using
  331. SQLite. This can be configured using the following::
  332. DATABASES = {
  333. 'default': {
  334. 'ENGINE': 'django.db.backends.sqlite3',
  335. 'NAME': 'mydatabase',
  336. }
  337. }
  338. When connecting to other database backends, such as MariaDB, MySQL, Oracle, or
  339. PostgreSQL, additional connection parameters will be required. See
  340. the :setting:`ENGINE <DATABASE-ENGINE>` setting below on how to specify
  341. other database types. This example is for PostgreSQL::
  342. DATABASES = {
  343. 'default': {
  344. 'ENGINE': 'django.db.backends.postgresql',
  345. 'NAME': 'mydatabase',
  346. 'USER': 'mydatabaseuser',
  347. 'PASSWORD': 'mypassword',
  348. 'HOST': '127.0.0.1',
  349. 'PORT': '5432',
  350. }
  351. }
  352. The following inner options that may be required for more complex
  353. configurations are available:
  354. .. setting:: DATABASE-ATOMIC_REQUESTS
  355. ``ATOMIC_REQUESTS``
  356. ~~~~~~~~~~~~~~~~~~~
  357. Default: ``False``
  358. Set this to ``True`` to wrap each view in a transaction on this database. See
  359. :ref:`tying-transactions-to-http-requests`.
  360. .. setting:: DATABASE-AUTOCOMMIT
  361. ``AUTOCOMMIT``
  362. ~~~~~~~~~~~~~~
  363. Default: ``True``
  364. Set this to ``False`` if you want to :ref:`disable Django's transaction
  365. management <deactivate-transaction-management>` and implement your own.
  366. .. setting:: DATABASE-ENGINE
  367. ``ENGINE``
  368. ~~~~~~~~~~
  369. Default: ``''`` (Empty string)
  370. The database backend to use. The built-in database backends are:
  371. * ``'django.db.backends.postgresql'``
  372. * ``'django.db.backends.mysql'``
  373. * ``'django.db.backends.sqlite3'``
  374. * ``'django.db.backends.oracle'``
  375. You can use a database backend that doesn't ship with Django by setting
  376. ``ENGINE`` to a fully-qualified path (i.e. ``mypackage.backends.whatever``).
  377. .. setting:: HOST
  378. ``HOST``
  379. ~~~~~~~~
  380. Default: ``''`` (Empty string)
  381. Which host to use when connecting to the database. An empty string means
  382. localhost. Not used with SQLite.
  383. If this value starts with a forward slash (``'/'``) and you're using MySQL,
  384. MySQL will connect via a Unix socket to the specified socket. For example::
  385. "HOST": '/var/run/mysql'
  386. If you're using MySQL and this value *doesn't* start with a forward slash, then
  387. this value is assumed to be the host.
  388. If you're using PostgreSQL, by default (empty :setting:`HOST`), the connection
  389. to the database is done through UNIX domain sockets ('local' lines in
  390. ``pg_hba.conf``). If your UNIX domain socket is not in the standard location,
  391. use the same value of ``unix_socket_directory`` from ``postgresql.conf``.
  392. If you want to connect through TCP sockets, set :setting:`HOST` to 'localhost'
  393. or '127.0.0.1' ('host' lines in ``pg_hba.conf``).
  394. On Windows, you should always define :setting:`HOST`, as UNIX domain sockets
  395. are not available.
  396. .. setting:: NAME
  397. ``NAME``
  398. ~~~~~~~~
  399. Default: ``''`` (Empty string)
  400. The name of the database to use. For SQLite, it's the full path to the database
  401. file. When specifying the path, always use forward slashes, even on Windows
  402. (e.g. ``C:/homes/user/mysite/sqlite3.db``).
  403. .. setting:: CONN_MAX_AGE
  404. ``CONN_MAX_AGE``
  405. ~~~~~~~~~~~~~~~~
  406. Default: ``0``
  407. The lifetime of a database connection, as an integer of seconds. Use ``0`` to
  408. close database connections at the end of each request — Django's historical
  409. behavior — and ``None`` for unlimited persistent connections.
  410. .. setting:: OPTIONS
  411. ``OPTIONS``
  412. ~~~~~~~~~~~
  413. Default: ``{}`` (Empty dictionary)
  414. Extra parameters to use when connecting to the database. Available parameters
  415. vary depending on your database backend.
  416. Some information on available parameters can be found in the
  417. :doc:`Database Backends </ref/databases>` documentation. For more information,
  418. consult your backend module's own documentation.
  419. .. setting:: PASSWORD
  420. ``PASSWORD``
  421. ~~~~~~~~~~~~
  422. Default: ``''`` (Empty string)
  423. The password to use when connecting to the database. Not used with SQLite.
  424. .. setting:: PORT
  425. ``PORT``
  426. ~~~~~~~~
  427. Default: ``''`` (Empty string)
  428. The port to use when connecting to the database. An empty string means the
  429. default port. Not used with SQLite.
  430. .. setting:: DATABASE-TIME_ZONE
  431. ``TIME_ZONE``
  432. ~~~~~~~~~~~~~
  433. Default: ``None``
  434. A string representing the time zone for this database connection or ``None``.
  435. This inner option of the :setting:`DATABASES` setting accepts the same values
  436. as the general :setting:`TIME_ZONE` setting.
  437. When :setting:`USE_TZ` is ``True`` and this option is set, reading datetimes
  438. from the database returns aware datetimes in this time zone instead of UTC.
  439. When :setting:`USE_TZ` is ``False``, it is an error to set this option.
  440. * If the database backend doesn't support time zones (e.g. SQLite, MySQL,
  441. Oracle), Django reads and writes datetimes in local time according to this
  442. option if it is set and in UTC if it isn't.
  443. Changing the connection time zone changes how datetimes are read from and
  444. written to the database.
  445. * If Django manages the database and you don't have a strong reason to do
  446. otherwise, you should leave this option unset. It's best to store datetimes
  447. in UTC because it avoids ambiguous or nonexistent datetimes during daylight
  448. saving time changes. Also, receiving datetimes in UTC keeps datetime
  449. arithmetic simple — there's no need for the ``normalize()`` method provided
  450. by pytz.
  451. * If you're connecting to a third-party database that stores datetimes in a
  452. local time rather than UTC, then you must set this option to the
  453. appropriate time zone. Likewise, if Django manages the database but
  454. third-party systems connect to the same database and expect to find
  455. datetimes in local time, then you must set this option.
  456. * If the database backend supports time zones (e.g. PostgreSQL), the
  457. ``TIME_ZONE`` option is very rarely needed. It can be changed at any time;
  458. the database takes care of converting datetimes to the desired time zone.
  459. Setting the time zone of the database connection may be useful for running
  460. raw SQL queries involving date/time functions provided by the database, such
  461. as ``date_trunc``, because their results depend on the time zone.
  462. However, this has a downside: receiving all datetimes in local time makes
  463. datetime arithmetic more tricky — you must call the ``normalize()`` method
  464. provided by pytz after each operation.
  465. Consider converting to local time explicitly with ``AT TIME ZONE`` in raw SQL
  466. queries instead of setting the ``TIME_ZONE`` option.
  467. .. versionchanged:: 3.1
  468. Using this option when the database backend supports time zones was allowed.
  469. .. setting:: DATABASE-DISABLE_SERVER_SIDE_CURSORS
  470. ``DISABLE_SERVER_SIDE_CURSORS``
  471. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  472. Default: ``False``
  473. Set this to ``True`` if you want to disable the use of server-side cursors with
  474. :meth:`.QuerySet.iterator`. :ref:`transaction-pooling-server-side-cursors`
  475. describes the use case.
  476. This is a PostgreSQL-specific setting.
  477. .. setting:: USER
  478. ``USER``
  479. ~~~~~~~~
  480. Default: ``''`` (Empty string)
  481. The username to use when connecting to the database. Not used with SQLite.
  482. .. setting:: DATABASE-TEST
  483. ``TEST``
  484. ~~~~~~~~
  485. Default: ``{}`` (Empty dictionary)
  486. A dictionary of settings for test databases; for more details about the
  487. creation and use of test databases, see :ref:`the-test-database`.
  488. Here's an example with a test database configuration::
  489. DATABASES = {
  490. 'default': {
  491. 'ENGINE': 'django.db.backends.postgresql',
  492. 'USER': 'mydatabaseuser',
  493. 'NAME': 'mydatabase',
  494. 'TEST': {
  495. 'NAME': 'mytestdatabase',
  496. },
  497. },
  498. }
  499. The following keys in the ``TEST`` dictionary are available:
  500. .. setting:: TEST_CHARSET
  501. ``CHARSET``
  502. ^^^^^^^^^^^
  503. Default: ``None``
  504. The character set encoding used to create the test database. The value of this
  505. string is passed directly through to the database, so its format is
  506. backend-specific.
  507. Supported by the PostgreSQL_ (``postgresql``) and MySQL_ (``mysql``) backends.
  508. .. _PostgreSQL: https://www.postgresql.org/docs/current/multibyte.html
  509. .. _MySQL: https://dev.mysql.com/doc/refman/en/charset-charsets.html
  510. .. setting:: TEST_COLLATION
  511. ``COLLATION``
  512. ^^^^^^^^^^^^^
  513. Default: ``None``
  514. The collation order to use when creating the test database. This value is
  515. passed directly to the backend, so its format is backend-specific.
  516. Only supported for the ``mysql`` backend (see the `MySQL manual`_ for details).
  517. .. _MySQL manual: MySQL_
  518. .. setting:: TEST_DEPENDENCIES
  519. ``DEPENDENCIES``
  520. ^^^^^^^^^^^^^^^^
  521. Default: ``['default']``, for all databases other than ``default``,
  522. which has no dependencies.
  523. The creation-order dependencies of the database. See the documentation
  524. on :ref:`controlling the creation order of test databases
  525. <topics-testing-creation-dependencies>` for details.
  526. .. setting:: TEST_MIGRATE
  527. ``MIGRATE``
  528. ^^^^^^^^^^^
  529. .. versionadded:: 3.1
  530. Default: ``True``
  531. When set to ``False``, migrations won't run when creating the test database.
  532. .. setting:: TEST_MIRROR
  533. ``MIRROR``
  534. ^^^^^^^^^^
  535. Default: ``None``
  536. The alias of the database that this database should mirror during
  537. testing.
  538. This setting exists to allow for testing of primary/replica
  539. (referred to as master/slave by some databases)
  540. configurations of multiple databases. See the documentation on
  541. :ref:`testing primary/replica configurations
  542. <topics-testing-primaryreplica>` for details.
  543. .. setting:: TEST_NAME
  544. ``NAME``
  545. ^^^^^^^^
  546. Default: ``None``
  547. The name of database to use when running the test suite.
  548. If the default value (``None``) is used with the SQLite database engine, the
  549. tests will use a memory resident database. For all other database engines the
  550. test database will use the name ``'test_' + DATABASE_NAME``.
  551. See :ref:`the-test-database`.
  552. .. setting:: TEST_SERIALIZE
  553. ``SERIALIZE``
  554. ^^^^^^^^^^^^^
  555. Boolean value to control whether or not the default test runner serializes the
  556. database into an in-memory JSON string before running tests (used to restore
  557. the database state between tests if you don't have transactions). You can set
  558. this to ``False`` to speed up creation time if you don't have any test classes
  559. with :ref:`serialized_rollback=True <test-case-serialized-rollback>`.
  560. .. setting:: TEST_TEMPLATE
  561. ``TEMPLATE``
  562. ^^^^^^^^^^^^
  563. This is a PostgreSQL-specific setting.
  564. The name of a `template`_ (e.g. ``'template0'``) from which to create the test
  565. database.
  566. .. _template: https://www.postgresql.org/docs/current/sql-createdatabase.html
  567. .. setting:: TEST_CREATE
  568. ``CREATE_DB``
  569. ^^^^^^^^^^^^^
  570. Default: ``True``
  571. This is an Oracle-specific setting.
  572. If it is set to ``False``, the test tablespaces won't be automatically created
  573. at the beginning of the tests or dropped at the end.
  574. .. setting:: TEST_USER_CREATE
  575. ``CREATE_USER``
  576. ^^^^^^^^^^^^^^^
  577. Default: ``True``
  578. This is an Oracle-specific setting.
  579. If it is set to ``False``, the test user won't be automatically created at the
  580. beginning of the tests and dropped at the end.
  581. .. setting:: TEST_USER
  582. ``USER``
  583. ^^^^^^^^
  584. Default: ``None``
  585. This is an Oracle-specific setting.
  586. The username to use when connecting to the Oracle database that will be used
  587. when running tests. If not provided, Django will use ``'test_' + USER``.
  588. .. setting:: TEST_PASSWD
  589. ``PASSWORD``
  590. ^^^^^^^^^^^^
  591. Default: ``None``
  592. This is an Oracle-specific setting.
  593. The password to use when connecting to the Oracle database that will be used
  594. when running tests. If not provided, Django will generate a random password.
  595. .. setting:: TEST_ORACLE_MANAGED_FILES
  596. ``ORACLE_MANAGED_FILES``
  597. ^^^^^^^^^^^^^^^^^^^^^^^^
  598. Default: ``False``
  599. This is an Oracle-specific setting.
  600. If set to ``True``, Oracle Managed Files (OMF) tablespaces will be used.
  601. :setting:`DATAFILE` and :setting:`DATAFILE_TMP` will be ignored.
  602. .. setting:: TEST_TBLSPACE
  603. ``TBLSPACE``
  604. ^^^^^^^^^^^^
  605. Default: ``None``
  606. This is an Oracle-specific setting.
  607. The name of the tablespace that will be used when running tests. If not
  608. provided, Django will use ``'test_' + USER``.
  609. .. setting:: TEST_TBLSPACE_TMP
  610. ``TBLSPACE_TMP``
  611. ^^^^^^^^^^^^^^^^
  612. Default: ``None``
  613. This is an Oracle-specific setting.
  614. The name of the temporary tablespace that will be used when running tests. If
  615. not provided, Django will use ``'test_' + USER + '_temp'``.
  616. .. setting:: DATAFILE
  617. ``DATAFILE``
  618. ^^^^^^^^^^^^
  619. Default: ``None``
  620. This is an Oracle-specific setting.
  621. The name of the datafile to use for the TBLSPACE. If not provided, Django will
  622. use ``TBLSPACE + '.dbf'``.
  623. .. setting:: DATAFILE_TMP
  624. ``DATAFILE_TMP``
  625. ^^^^^^^^^^^^^^^^
  626. Default: ``None``
  627. This is an Oracle-specific setting.
  628. The name of the datafile to use for the TBLSPACE_TMP. If not provided, Django
  629. will use ``TBLSPACE_TMP + '.dbf'``.
  630. .. setting:: DATAFILE_MAXSIZE
  631. ``DATAFILE_MAXSIZE``
  632. ^^^^^^^^^^^^^^^^^^^^
  633. Default: ``'500M'``
  634. This is an Oracle-specific setting.
  635. The maximum size that the DATAFILE is allowed to grow to.
  636. .. setting:: DATAFILE_TMP_MAXSIZE
  637. ``DATAFILE_TMP_MAXSIZE``
  638. ^^^^^^^^^^^^^^^^^^^^^^^^
  639. Default: ``'500M'``
  640. This is an Oracle-specific setting.
  641. The maximum size that the DATAFILE_TMP is allowed to grow to.
  642. .. setting:: DATAFILE_SIZE
  643. ``DATAFILE_SIZE``
  644. ^^^^^^^^^^^^^^^^^
  645. Default: ``'50M'``
  646. This is an Oracle-specific setting.
  647. The initial size of the DATAFILE.
  648. .. setting:: DATAFILE_TMP_SIZE
  649. ``DATAFILE_TMP_SIZE``
  650. ^^^^^^^^^^^^^^^^^^^^^
  651. Default: ``'50M'``
  652. This is an Oracle-specific setting.
  653. The initial size of the DATAFILE_TMP.
  654. .. setting:: DATAFILE_EXTSIZE
  655. ``DATAFILE_EXTSIZE``
  656. ^^^^^^^^^^^^^^^^^^^^
  657. Default: ``'25M'``
  658. This is an Oracle-specific setting.
  659. The amount by which the DATAFILE is extended when more space is required.
  660. .. setting:: DATAFILE_TMP_EXTSIZE
  661. ``DATAFILE_TMP_EXTSIZE``
  662. ^^^^^^^^^^^^^^^^^^^^^^^^
  663. Default: ``'25M'``
  664. This is an Oracle-specific setting.
  665. The amount by which the DATAFILE_TMP is extended when more space is required.
  666. .. setting:: DATA_UPLOAD_MAX_MEMORY_SIZE
  667. DATA_UPLOAD_MAX_MEMORY_SIZE
  668. ---------------------------
  669. Default: ``2621440`` (i.e. 2.5 MB).
  670. The maximum size in bytes that a request body may be before a
  671. :exc:`~django.core.exceptions.SuspiciousOperation` (``RequestDataTooBig``) is
  672. raised. The check is done when accessing ``request.body`` or ``request.POST``
  673. and is calculated against the total request size excluding any file upload
  674. data. You can set this to ``None`` to disable the check. Applications that are
  675. expected to receive unusually large form posts should tune this setting.
  676. The amount of request data is correlated to the amount of memory needed to
  677. process the request and populate the GET and POST dictionaries. Large requests
  678. could be used as a denial-of-service attack vector if left unchecked. Since web
  679. servers don't typically perform deep request inspection, it's not possible to
  680. perform a similar check at that level.
  681. See also :setting:`FILE_UPLOAD_MAX_MEMORY_SIZE`.
  682. .. setting:: DATA_UPLOAD_MAX_NUMBER_FIELDS
  683. DATA_UPLOAD_MAX_NUMBER_FIELDS
  684. -----------------------------
  685. Default: ``1000``
  686. The maximum number of parameters that may be received via GET or POST before a
  687. :exc:`~django.core.exceptions.SuspiciousOperation` (``TooManyFields``) is
  688. raised. You can set this to ``None`` to disable the check. Applications that
  689. are expected to receive an unusually large number of form fields should tune
  690. this setting.
  691. The number of request parameters is correlated to the amount of time needed to
  692. process the request and populate the GET and POST dictionaries. Large requests
  693. could be used as a denial-of-service attack vector if left unchecked. Since web
  694. servers don't typically perform deep request inspection, it's not possible to
  695. perform a similar check at that level.
  696. .. setting:: DATABASE_ROUTERS
  697. ``DATABASE_ROUTERS``
  698. --------------------
  699. Default: ``[]`` (Empty list)
  700. The list of routers that will be used to determine which database
  701. to use when performing a database query.
  702. See the documentation on :ref:`automatic database routing in multi
  703. database configurations <topics-db-multi-db-routing>`.
  704. .. setting:: DATE_FORMAT
  705. ``DATE_FORMAT``
  706. ---------------
  707. Default: ``'N j, Y'`` (e.g. ``Feb. 4, 2003``)
  708. The default formatting to use for displaying date fields in any part of the
  709. system. Note that if :setting:`USE_L10N` is set to ``True``, then the
  710. locale-dictated format has higher precedence and will be applied instead. See
  711. :tfilter:`allowed date format strings <date>`.
  712. See also :setting:`DATETIME_FORMAT`, :setting:`TIME_FORMAT` and :setting:`SHORT_DATE_FORMAT`.
  713. .. setting:: DATE_INPUT_FORMATS
  714. ``DATE_INPUT_FORMATS``
  715. ----------------------
  716. Default::
  717. [
  718. '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06'
  719. '%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006'
  720. '%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006'
  721. '%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006'
  722. '%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006'
  723. ]
  724. A list of formats that will be accepted when inputting data on a date field.
  725. Formats will be tried in order, using the first valid one. Note that these
  726. format strings use Python's :ref:`datetime module syntax
  727. <strftime-strptime-behavior>`, not the format strings from the :tfilter:`date`
  728. template filter.
  729. When :setting:`USE_L10N` is ``True``, the locale-dictated format has higher
  730. precedence and will be applied instead.
  731. See also :setting:`DATETIME_INPUT_FORMATS` and :setting:`TIME_INPUT_FORMATS`.
  732. .. setting:: DATETIME_FORMAT
  733. ``DATETIME_FORMAT``
  734. -------------------
  735. Default: ``'N j, Y, P'`` (e.g. ``Feb. 4, 2003, 4 p.m.``)
  736. The default formatting to use for displaying datetime fields in any part of the
  737. system. Note that if :setting:`USE_L10N` is set to ``True``, then the
  738. locale-dictated format has higher precedence and will be applied instead. See
  739. :tfilter:`allowed date format strings <date>`.
  740. See also :setting:`DATE_FORMAT`, :setting:`TIME_FORMAT` and :setting:`SHORT_DATETIME_FORMAT`.
  741. .. setting:: DATETIME_INPUT_FORMATS
  742. ``DATETIME_INPUT_FORMATS``
  743. --------------------------
  744. Default::
  745. [
  746. '%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
  747. '%Y-%m-%d %H:%M:%S.%f', # '2006-10-25 14:30:59.000200'
  748. '%Y-%m-%d %H:%M', # '2006-10-25 14:30'
  749. '%m/%d/%Y %H:%M:%S', # '10/25/2006 14:30:59'
  750. '%m/%d/%Y %H:%M:%S.%f', # '10/25/2006 14:30:59.000200'
  751. '%m/%d/%Y %H:%M', # '10/25/2006 14:30'
  752. '%m/%d/%y %H:%M:%S', # '10/25/06 14:30:59'
  753. '%m/%d/%y %H:%M:%S.%f', # '10/25/06 14:30:59.000200'
  754. '%m/%d/%y %H:%M', # '10/25/06 14:30'
  755. ]
  756. A list of formats that will be accepted when inputting data on a datetime
  757. field. Formats will be tried in order, using the first valid one. Note that
  758. these format strings use Python's :ref:`datetime module syntax
  759. <strftime-strptime-behavior>`, not the format strings from the :tfilter:`date`
  760. template filter. Date-only formats are not included as datetime fields will
  761. automatically try :setting:`DATE_INPUT_FORMATS` in last resort.
  762. When :setting:`USE_L10N` is ``True``, the locale-dictated format has higher
  763. precedence and will be applied instead.
  764. See also :setting:`DATE_INPUT_FORMATS` and :setting:`TIME_INPUT_FORMATS`.
  765. .. versionchanged:: 3.1
  766. In older versions, the default is a list containing also date-only formats.
  767. .. setting:: DEBUG
  768. ``DEBUG``
  769. ---------
  770. Default: ``False``
  771. A boolean that turns on/off debug mode.
  772. Never deploy a site into production with :setting:`DEBUG` turned on.
  773. One of the main features of debug mode is the display of detailed error pages.
  774. If your app raises an exception when :setting:`DEBUG` is ``True``, Django will
  775. display a detailed traceback, including a lot of metadata about your
  776. environment, such as all the currently defined Django settings (from
  777. ``settings.py``).
  778. As a security measure, Django will *not* include settings that might be
  779. sensitive, such as :setting:`SECRET_KEY`. Specifically, it will exclude any
  780. setting whose name includes any of the following:
  781. * ``'API'``
  782. * ``'KEY'``
  783. * ``'PASS'``
  784. * ``'SECRET'``
  785. * ``'SIGNATURE'``
  786. * ``'TOKEN'``
  787. Note that these are *partial* matches. ``'PASS'`` will also match PASSWORD,
  788. just as ``'TOKEN'`` will also match TOKENIZED and so on.
  789. Still, note that there are always going to be sections of your debug output
  790. that are inappropriate for public consumption. File paths, configuration
  791. options and the like all give attackers extra information about your server.
  792. It is also important to remember that when running with :setting:`DEBUG`
  793. turned on, Django will remember every SQL query it executes. This is useful
  794. when you're debugging, but it'll rapidly consume memory on a production server.
  795. Finally, if :setting:`DEBUG` is ``False``, you also need to properly set
  796. the :setting:`ALLOWED_HOSTS` setting. Failing to do so will result in all
  797. requests being returned as "Bad Request (400)".
  798. .. note::
  799. The default :file:`settings.py` file created by :djadmin:`django-admin
  800. startproject <startproject>` sets ``DEBUG = True`` for convenience.
  801. .. setting:: DEBUG_PROPAGATE_EXCEPTIONS
  802. ``DEBUG_PROPAGATE_EXCEPTIONS``
  803. ------------------------------
  804. Default: ``False``
  805. If set to ``True``, Django's exception handling of view functions
  806. (:data:`~django.conf.urls.handler500`, or the debug view if :setting:`DEBUG`
  807. is ``True``) and logging of 500 responses (:ref:`django-request-logger`) is
  808. skipped and exceptions propagate upwards.
  809. This can be useful for some test setups. It shouldn't be used on a live site
  810. unless you want your web server (instead of Django) to generate "Internal
  811. Server Error" responses. In that case, make sure your server doesn't show the
  812. stack trace or other sensitive information in the response.
  813. .. setting:: DECIMAL_SEPARATOR
  814. ``DECIMAL_SEPARATOR``
  815. ---------------------
  816. Default: ``'.'`` (Dot)
  817. Default decimal separator used when formatting decimal numbers.
  818. Note that if :setting:`USE_L10N` is set to ``True``, then the locale-dictated
  819. format has higher precedence and will be applied instead.
  820. See also :setting:`NUMBER_GROUPING`, :setting:`THOUSAND_SEPARATOR` and
  821. :setting:`USE_THOUSAND_SEPARATOR`.
  822. .. setting:: DEFAULT_CHARSET
  823. ``DEFAULT_CHARSET``
  824. -------------------
  825. Default: ``'utf-8'``
  826. Default charset to use for all ``HttpResponse`` objects, if a MIME type isn't
  827. manually specified. Used when constructing the ``Content-Type`` header.
  828. .. setting:: DEFAULT_EXCEPTION_REPORTER
  829. ``DEFAULT_EXCEPTION_REPORTER``
  830. ------------------------------
  831. .. versionadded:: 3.1
  832. Default: ``'``:class:`django.views.debug.ExceptionReporter`\ ``'``
  833. Default exception reporter class to be used if none has been assigned to the
  834. :class:`~django.http.HttpRequest` instance yet. See
  835. :ref:`custom-error-reports`.
  836. .. setting:: DEFAULT_EXCEPTION_REPORTER_FILTER
  837. ``DEFAULT_EXCEPTION_REPORTER_FILTER``
  838. -------------------------------------
  839. Default: ``'``:class:`django.views.debug.SafeExceptionReporterFilter`\ ``'``
  840. Default exception reporter filter class to be used if none has been assigned to
  841. the :class:`~django.http.HttpRequest` instance yet.
  842. See :ref:`Filtering error reports<filtering-error-reports>`.
  843. .. setting:: DEFAULT_FILE_STORAGE
  844. ``DEFAULT_FILE_STORAGE``
  845. ------------------------
  846. Default: ``'``:class:`django.core.files.storage.FileSystemStorage`\ ``'``
  847. Default file storage class to be used for any file-related operations that don't
  848. specify a particular storage system. See :doc:`/topics/files`.
  849. .. setting:: DEFAULT_FROM_EMAIL
  850. ``DEFAULT_FROM_EMAIL``
  851. ----------------------
  852. Default: ``'webmaster@localhost'``
  853. Default email address to use for various automated correspondence from the
  854. site manager(s). This doesn't include error messages sent to :setting:`ADMINS`
  855. and :setting:`MANAGERS`; for that, see :setting:`SERVER_EMAIL`.
  856. .. setting:: DEFAULT_HASHING_ALGORITHM
  857. ``DEFAULT_HASHING_ALGORITHM``
  858. -----------------------------
  859. .. versionadded:: 3.1
  860. Default: ``'sha256'``
  861. Default hashing algorithm to use for encoding cookies, password reset tokens in
  862. the admin site, user sessions, and signatures created by
  863. :class:`django.core.signing.Signer` and :meth:`django.core.signing.dumps`.
  864. Algorithm must be ``'sha1'`` or ``'sha256'``. See
  865. :ref:`release notes <default-hashing-algorithm-usage>` for usage details.
  866. .. deprecated:: 3.1
  867. This transitional setting is deprecated. Support for it and tokens,
  868. cookies, sessions, and signatures that use SHA-1 hashing algorithm will be
  869. removed in Django 4.0.
  870. .. setting:: DEFAULT_INDEX_TABLESPACE
  871. ``DEFAULT_INDEX_TABLESPACE``
  872. ----------------------------
  873. Default: ``''`` (Empty string)
  874. Default tablespace to use for indexes on fields that don't specify
  875. one, if the backend supports it (see :doc:`/topics/db/tablespaces`).
  876. .. setting:: DEFAULT_TABLESPACE
  877. ``DEFAULT_TABLESPACE``
  878. ----------------------
  879. Default: ``''`` (Empty string)
  880. Default tablespace to use for models that don't specify one, if the
  881. backend supports it (see :doc:`/topics/db/tablespaces`).
  882. .. setting:: DISALLOWED_USER_AGENTS
  883. ``DISALLOWED_USER_AGENTS``
  884. --------------------------
  885. Default: ``[]`` (Empty list)
  886. List of compiled regular expression objects representing User-Agent strings
  887. that are not allowed to visit any page, systemwide. Use this for bots/crawlers.
  888. This is only used if ``CommonMiddleware`` is installed (see
  889. :doc:`/topics/http/middleware`).
  890. .. setting:: EMAIL_BACKEND
  891. ``EMAIL_BACKEND``
  892. -----------------
  893. Default: ``'``:class:`django.core.mail.backends.smtp.EmailBackend`\ ``'``
  894. The backend to use for sending emails. For the list of available backends see
  895. :doc:`/topics/email`.
  896. .. setting:: EMAIL_FILE_PATH
  897. ``EMAIL_FILE_PATH``
  898. -------------------
  899. Default: Not defined
  900. The directory used by the :ref:`file email backend <topic-email-file-backend>`
  901. to store output files.
  902. .. versionchanged:: 3.1
  903. Support for :class:`pathlib.Path` was added.
  904. .. setting:: EMAIL_HOST
  905. ``EMAIL_HOST``
  906. --------------
  907. Default: ``'localhost'``
  908. The host to use for sending email.
  909. See also :setting:`EMAIL_PORT`.
  910. .. setting:: EMAIL_HOST_PASSWORD
  911. ``EMAIL_HOST_PASSWORD``
  912. -----------------------
  913. Default: ``''`` (Empty string)
  914. Password to use for the SMTP server defined in :setting:`EMAIL_HOST`. This
  915. setting is used in conjunction with :setting:`EMAIL_HOST_USER` when
  916. authenticating to the SMTP server. If either of these settings is empty,
  917. Django won't attempt authentication.
  918. See also :setting:`EMAIL_HOST_USER`.
  919. .. setting:: EMAIL_HOST_USER
  920. ``EMAIL_HOST_USER``
  921. -------------------
  922. Default: ``''`` (Empty string)
  923. Username to use for the SMTP server defined in :setting:`EMAIL_HOST`.
  924. If empty, Django won't attempt authentication.
  925. See also :setting:`EMAIL_HOST_PASSWORD`.
  926. .. setting:: EMAIL_PORT
  927. ``EMAIL_PORT``
  928. --------------
  929. Default: ``25``
  930. Port to use for the SMTP server defined in :setting:`EMAIL_HOST`.
  931. .. setting:: EMAIL_SUBJECT_PREFIX
  932. ``EMAIL_SUBJECT_PREFIX``
  933. ------------------------
  934. Default: ``'[Django] '``
  935. Subject-line prefix for email messages sent with ``django.core.mail.mail_admins``
  936. or ``django.core.mail.mail_managers``. You'll probably want to include the
  937. trailing space.
  938. .. setting:: EMAIL_USE_LOCALTIME
  939. ``EMAIL_USE_LOCALTIME``
  940. -----------------------
  941. Default: ``False``
  942. Whether to send the SMTP ``Date`` header of email messages in the local time
  943. zone (``True``) or in UTC (``False``).
  944. .. setting:: EMAIL_USE_TLS
  945. ``EMAIL_USE_TLS``
  946. -----------------
  947. Default: ``False``
  948. Whether to use a TLS (secure) connection when talking to the SMTP server.
  949. This is used for explicit TLS connections, generally on port 587. If you are
  950. experiencing hanging connections, see the implicit TLS setting
  951. :setting:`EMAIL_USE_SSL`.
  952. .. setting:: EMAIL_USE_SSL
  953. ``EMAIL_USE_SSL``
  954. -----------------
  955. Default: ``False``
  956. Whether to use an implicit TLS (secure) connection when talking to the SMTP
  957. server. In most email documentation this type of TLS connection is referred
  958. to as SSL. It is generally used on port 465. If you are experiencing problems,
  959. see the explicit TLS setting :setting:`EMAIL_USE_TLS`.
  960. Note that :setting:`EMAIL_USE_TLS`/:setting:`EMAIL_USE_SSL` are mutually
  961. exclusive, so only set one of those settings to ``True``.
  962. .. setting:: EMAIL_SSL_CERTFILE
  963. ``EMAIL_SSL_CERTFILE``
  964. ----------------------
  965. Default: ``None``
  966. If :setting:`EMAIL_USE_SSL` or :setting:`EMAIL_USE_TLS` is ``True``, you can
  967. optionally specify the path to a PEM-formatted certificate chain file to use
  968. for the SSL connection.
  969. .. setting:: EMAIL_SSL_KEYFILE
  970. ``EMAIL_SSL_KEYFILE``
  971. ---------------------
  972. Default: ``None``
  973. If :setting:`EMAIL_USE_SSL` or :setting:`EMAIL_USE_TLS` is ``True``, you can
  974. optionally specify the path to a PEM-formatted private key file to use for the
  975. SSL connection.
  976. Note that setting :setting:`EMAIL_SSL_CERTFILE` and :setting:`EMAIL_SSL_KEYFILE`
  977. doesn't result in any certificate checking. They're passed to the underlying SSL
  978. connection. Please refer to the documentation of Python's
  979. :func:`python:ssl.wrap_socket` function for details on how the certificate chain
  980. file and private key file are handled.
  981. .. setting:: EMAIL_TIMEOUT
  982. ``EMAIL_TIMEOUT``
  983. -----------------
  984. Default: ``None``
  985. Specifies a timeout in seconds for blocking operations like the connection
  986. attempt.
  987. .. setting:: FILE_UPLOAD_HANDLERS
  988. ``FILE_UPLOAD_HANDLERS``
  989. ------------------------
  990. Default::
  991. [
  992. 'django.core.files.uploadhandler.MemoryFileUploadHandler',
  993. 'django.core.files.uploadhandler.TemporaryFileUploadHandler',
  994. ]
  995. A list of handlers to use for uploading. Changing this setting allows complete
  996. customization -- even replacement -- of Django's upload process.
  997. See :doc:`/topics/files` for details.
  998. .. setting:: FILE_UPLOAD_MAX_MEMORY_SIZE
  999. ``FILE_UPLOAD_MAX_MEMORY_SIZE``
  1000. -------------------------------
  1001. Default: ``2621440`` (i.e. 2.5 MB).
  1002. The maximum size (in bytes) that an upload will be before it gets streamed to
  1003. the file system. See :doc:`/topics/files` for details.
  1004. See also :setting:`DATA_UPLOAD_MAX_MEMORY_SIZE`.
  1005. .. setting:: FILE_UPLOAD_DIRECTORY_PERMISSIONS
  1006. ``FILE_UPLOAD_DIRECTORY_PERMISSIONS``
  1007. -------------------------------------
  1008. Default: ``None``
  1009. The numeric mode to apply to directories created in the process of uploading
  1010. files.
  1011. This setting also determines the default permissions for collected static
  1012. directories when using the :djadmin:`collectstatic` management command. See
  1013. :djadmin:`collectstatic` for details on overriding it.
  1014. This value mirrors the functionality and caveats of the
  1015. :setting:`FILE_UPLOAD_PERMISSIONS` setting.
  1016. .. setting:: FILE_UPLOAD_PERMISSIONS
  1017. ``FILE_UPLOAD_PERMISSIONS``
  1018. ---------------------------
  1019. Default: ``0o644``
  1020. The numeric mode (i.e. ``0o644``) to set newly uploaded files to. For
  1021. more information about what these modes mean, see the documentation for
  1022. :func:`os.chmod`.
  1023. If ``None``, you'll get operating-system dependent behavior. On most platforms,
  1024. temporary files will have a mode of ``0o600``, and files saved from memory will
  1025. be saved using the system's standard umask.
  1026. For security reasons, these permissions aren't applied to the temporary files
  1027. that are stored in :setting:`FILE_UPLOAD_TEMP_DIR`.
  1028. This setting also determines the default permissions for collected static files
  1029. when using the :djadmin:`collectstatic` management command. See
  1030. :djadmin:`collectstatic` for details on overriding it.
  1031. .. warning::
  1032. **Always prefix the mode with** ``0o`` **.**
  1033. If you're not familiar with file modes, please note that the ``0o`` prefix
  1034. is very important: it indicates an octal number, which is the way that
  1035. modes must be specified. If you try to use ``644``, you'll get totally
  1036. incorrect behavior.
  1037. .. setting:: FILE_UPLOAD_TEMP_DIR
  1038. ``FILE_UPLOAD_TEMP_DIR``
  1039. ------------------------
  1040. Default: ``None``
  1041. The directory to store data to (typically files larger than
  1042. :setting:`FILE_UPLOAD_MAX_MEMORY_SIZE`) temporarily while uploading files.
  1043. If ``None``, Django will use the standard temporary directory for the operating
  1044. system. For example, this will default to ``/tmp`` on \*nix-style operating
  1045. systems.
  1046. See :doc:`/topics/files` for details.
  1047. .. setting:: FIRST_DAY_OF_WEEK
  1048. ``FIRST_DAY_OF_WEEK``
  1049. ---------------------
  1050. Default: ``0`` (Sunday)
  1051. A number representing the first day of the week. This is especially useful
  1052. when displaying a calendar. This value is only used when not using
  1053. format internationalization, or when a format cannot be found for the
  1054. current locale.
  1055. The value must be an integer from 0 to 6, where 0 means Sunday, 1 means
  1056. Monday and so on.
  1057. .. setting:: FIXTURE_DIRS
  1058. ``FIXTURE_DIRS``
  1059. ----------------
  1060. Default: ``[]`` (Empty list)
  1061. List of directories searched for fixture files, in addition to the
  1062. ``fixtures`` directory of each application, in search order.
  1063. Note that these paths should use Unix-style forward slashes, even on Windows.
  1064. See :ref:`initial-data-via-fixtures` and :ref:`topics-testing-fixtures`.
  1065. .. setting:: FORCE_SCRIPT_NAME
  1066. ``FORCE_SCRIPT_NAME``
  1067. ---------------------
  1068. Default: ``None``
  1069. If not ``None``, this will be used as the value of the ``SCRIPT_NAME``
  1070. environment variable in any HTTP request. This setting can be used to override
  1071. the server-provided value of ``SCRIPT_NAME``, which may be a rewritten version
  1072. of the preferred value or not supplied at all. It is also used by
  1073. :func:`django.setup()` to set the URL resolver script prefix outside of the
  1074. request/response cycle (e.g. in management commands and standalone scripts) to
  1075. generate correct URLs when ``SCRIPT_NAME`` is not ``/``.
  1076. .. setting:: FORM_RENDERER
  1077. ``FORM_RENDERER``
  1078. -----------------
  1079. Default: ``'``:class:`django.forms.renderers.DjangoTemplates`\ ``'``
  1080. The class that renders form widgets. It must implement :ref:`the low-level
  1081. render API <low-level-widget-render-api>`.
  1082. .. setting:: FORMAT_MODULE_PATH
  1083. ``FORMAT_MODULE_PATH``
  1084. ----------------------
  1085. Default: ``None``
  1086. A full Python path to a Python package that contains custom format definitions
  1087. for project locales. If not ``None``, Django will check for a ``formats.py``
  1088. file, under the directory named as the current locale, and will use the
  1089. formats defined in this file.
  1090. For example, if :setting:`FORMAT_MODULE_PATH` is set to ``mysite.formats``,
  1091. and current language is ``en`` (English), Django will expect a directory tree
  1092. like::
  1093. mysite/
  1094. formats/
  1095. __init__.py
  1096. en/
  1097. __init__.py
  1098. formats.py
  1099. You can also set this setting to a list of Python paths, for example::
  1100. FORMAT_MODULE_PATH = [
  1101. 'mysite.formats',
  1102. 'some_app.formats',
  1103. ]
  1104. When Django searches for a certain format, it will go through all given Python
  1105. paths until it finds a module that actually defines the given format. This
  1106. means that formats defined in packages farther up in the list will take
  1107. precedence over the same formats in packages farther down.
  1108. Available formats are:
  1109. * :setting:`DATE_FORMAT`
  1110. * :setting:`DATE_INPUT_FORMATS`
  1111. * :setting:`DATETIME_FORMAT`,
  1112. * :setting:`DATETIME_INPUT_FORMATS`
  1113. * :setting:`DECIMAL_SEPARATOR`
  1114. * :setting:`FIRST_DAY_OF_WEEK`
  1115. * :setting:`MONTH_DAY_FORMAT`
  1116. * :setting:`NUMBER_GROUPING`
  1117. * :setting:`SHORT_DATE_FORMAT`
  1118. * :setting:`SHORT_DATETIME_FORMAT`
  1119. * :setting:`THOUSAND_SEPARATOR`
  1120. * :setting:`TIME_FORMAT`
  1121. * :setting:`TIME_INPUT_FORMATS`
  1122. * :setting:`YEAR_MONTH_FORMAT`
  1123. .. setting:: IGNORABLE_404_URLS
  1124. ``IGNORABLE_404_URLS``
  1125. ----------------------
  1126. Default: ``[]`` (Empty list)
  1127. List of compiled regular expression objects describing URLs that should be
  1128. ignored when reporting HTTP 404 errors via email (see
  1129. :doc:`/howto/error-reporting`). Regular expressions are matched against
  1130. :meth:`request's full paths <django.http.HttpRequest.get_full_path>` (including
  1131. query string, if any). Use this if your site does not provide a commonly
  1132. requested file such as ``favicon.ico`` or ``robots.txt``.
  1133. This is only used if
  1134. :class:`~django.middleware.common.BrokenLinkEmailsMiddleware` is enabled (see
  1135. :doc:`/topics/http/middleware`).
  1136. .. setting:: INSTALLED_APPS
  1137. ``INSTALLED_APPS``
  1138. ------------------
  1139. Default: ``[]`` (Empty list)
  1140. A list of strings designating all applications that are enabled in this
  1141. Django installation. Each string should be a dotted Python path to:
  1142. * an application configuration class (preferred), or
  1143. * a package containing an application.
  1144. :doc:`Learn more about application configurations </ref/applications>`.
  1145. .. admonition:: Use the application registry for introspection
  1146. Your code should never access :setting:`INSTALLED_APPS` directly. Use
  1147. :attr:`django.apps.apps` instead.
  1148. .. admonition:: Application names and labels must be unique in
  1149. :setting:`INSTALLED_APPS`
  1150. Application :attr:`names <django.apps.AppConfig.name>` — the dotted Python
  1151. path to the application package — must be unique. There is no way to
  1152. include the same application twice, short of duplicating its code under
  1153. another name.
  1154. Application :attr:`labels <django.apps.AppConfig.label>` — by default the
  1155. final part of the name — must be unique too. For example, you can't
  1156. include both ``django.contrib.auth`` and ``myproject.auth``. However, you
  1157. can relabel an application with a custom configuration that defines a
  1158. different :attr:`~django.apps.AppConfig.label`.
  1159. These rules apply regardless of whether :setting:`INSTALLED_APPS`
  1160. references application configuration classes or application packages.
  1161. When several applications provide different versions of the same resource
  1162. (template, static file, management command, translation), the application
  1163. listed first in :setting:`INSTALLED_APPS` has precedence.
  1164. .. setting:: INTERNAL_IPS
  1165. ``INTERNAL_IPS``
  1166. ----------------
  1167. Default: ``[]`` (Empty list)
  1168. A list of IP addresses, as strings, that:
  1169. * Allow the :func:`~django.template.context_processors.debug` context processor
  1170. to add some variables to the template context.
  1171. * Can use the :ref:`admindocs bookmarklets <admindocs-bookmarklets>` even if
  1172. not logged in as a staff user.
  1173. * Are marked as "internal" (as opposed to "EXTERNAL") in
  1174. :class:`~django.utils.log.AdminEmailHandler` emails.
  1175. .. setting:: LANGUAGE_CODE
  1176. ``LANGUAGE_CODE``
  1177. -----------------
  1178. Default: ``'en-us'``
  1179. A string representing the language code for this installation. This should be in
  1180. standard :term:`language ID format <language code>`. For example, U.S. English
  1181. is ``"en-us"``. See also the `list of language identifiers`_ and
  1182. :doc:`/topics/i18n/index`.
  1183. :setting:`USE_I18N` must be active for this setting to have any effect.
  1184. It serves two purposes:
  1185. * If the locale middleware isn't in use, it decides which translation is served
  1186. to all users.
  1187. * If the locale middleware is active, it provides a fallback language in case the
  1188. user's preferred language can't be determined or is not supported by the
  1189. website. It also provides the fallback translation when a translation for a
  1190. given literal doesn't exist for the user's preferred language.
  1191. See :ref:`how-django-discovers-language-preference` for more details.
  1192. .. _list of language identifiers: http://www.i18nguy.com/unicode/language-identifiers.html
  1193. .. setting:: LANGUAGE_COOKIE_AGE
  1194. ``LANGUAGE_COOKIE_AGE``
  1195. -----------------------
  1196. Default: ``None`` (expires at browser close)
  1197. The age of the language cookie, in seconds.
  1198. .. setting:: LANGUAGE_COOKIE_DOMAIN
  1199. ``LANGUAGE_COOKIE_DOMAIN``
  1200. --------------------------
  1201. Default: ``None``
  1202. The domain to use for the language cookie. Set this to a string such as
  1203. ``"example.com"`` for cross-domain cookies, or use ``None`` for a standard
  1204. domain cookie.
  1205. Be cautious when updating this setting on a production site. If you update
  1206. this setting to enable cross-domain cookies on a site that previously used
  1207. standard domain cookies, existing user cookies that have the old domain
  1208. will not be updated. This will result in site users being unable to switch
  1209. the language as long as these cookies persist. The only safe and reliable
  1210. option to perform the switch is to change the language cookie name
  1211. permanently (via the :setting:`LANGUAGE_COOKIE_NAME` setting) and to add
  1212. a middleware that copies the value from the old cookie to a new one and then
  1213. deletes the old one.
  1214. .. setting:: LANGUAGE_COOKIE_HTTPONLY
  1215. ``LANGUAGE_COOKIE_HTTPONLY``
  1216. ----------------------------
  1217. Default: ``False``
  1218. Whether to use ``HttpOnly`` flag on the language cookie. If this is set to
  1219. ``True``, client-side JavaScript will not be able to access the language
  1220. cookie.
  1221. See :setting:`SESSION_COOKIE_HTTPONLY` for details on ``HttpOnly``.
  1222. .. setting:: LANGUAGE_COOKIE_NAME
  1223. ``LANGUAGE_COOKIE_NAME``
  1224. ------------------------
  1225. Default: ``'django_language'``
  1226. The name of the cookie to use for the language cookie. This can be whatever
  1227. you want (as long as it's different from the other cookie names in your
  1228. application). See :doc:`/topics/i18n/index`.
  1229. .. setting:: LANGUAGE_COOKIE_PATH
  1230. ``LANGUAGE_COOKIE_PATH``
  1231. ------------------------
  1232. Default: ``'/'``
  1233. The path set on the language cookie. This should either match the URL path of your
  1234. Django installation or be a parent of that path.
  1235. This is useful if you have multiple Django instances running under the same
  1236. hostname. They can use different cookie paths and each instance will only see
  1237. its own language cookie.
  1238. Be cautious when updating this setting on a production site. If you update this
  1239. setting to use a deeper path than it previously used, existing user cookies that
  1240. have the old path will not be updated. This will result in site users being
  1241. unable to switch the language as long as these cookies persist. The only safe
  1242. and reliable option to perform the switch is to change the language cookie name
  1243. permanently (via the :setting:`LANGUAGE_COOKIE_NAME` setting), and to add
  1244. a middleware that copies the value from the old cookie to a new one and then
  1245. deletes the one.
  1246. .. setting:: LANGUAGE_COOKIE_SAMESITE
  1247. ``LANGUAGE_COOKIE_SAMESITE``
  1248. ----------------------------
  1249. Default: ``None``
  1250. The value of the `SameSite`_ flag on the language cookie. This flag prevents the
  1251. cookie from being sent in cross-site requests.
  1252. See :setting:`SESSION_COOKIE_SAMESITE` for details about ``SameSite``.
  1253. .. versionchanged:: 3.1
  1254. Setting ``LANGUAGE_COOKIE_SAMESITE = 'None'`` was allowed.
  1255. .. setting:: LANGUAGE_COOKIE_SECURE
  1256. ``LANGUAGE_COOKIE_SECURE``
  1257. --------------------------
  1258. Default: ``False``
  1259. Whether to use a secure cookie for the language cookie. If this is set to
  1260. ``True``, the cookie will be marked as "secure", which means browsers may
  1261. ensure that the cookie is only sent under an HTTPS connection.
  1262. .. setting:: LANGUAGES
  1263. ``LANGUAGES``
  1264. -------------
  1265. Default: A list of all available languages. This list is continually growing
  1266. and including a copy here would inevitably become rapidly out of date. You can
  1267. see the current list of translated languages by looking in
  1268. :source:`django/conf/global_settings.py`.
  1269. The list is a list of two-tuples in the format
  1270. (:term:`language code<language code>`, ``language name``) -- for example,
  1271. ``('ja', 'Japanese')``.
  1272. This specifies which languages are available for language selection. See
  1273. :doc:`/topics/i18n/index`.
  1274. Generally, the default value should suffice. Only set this setting if you want
  1275. to restrict language selection to a subset of the Django-provided languages.
  1276. If you define a custom :setting:`LANGUAGES` setting, you can mark the
  1277. language names as translation strings using the
  1278. :func:`~django.utils.translation.gettext_lazy` function.
  1279. Here's a sample settings file::
  1280. from django.utils.translation import gettext_lazy as _
  1281. LANGUAGES = [
  1282. ('de', _('German')),
  1283. ('en', _('English')),
  1284. ]
  1285. .. setting:: LANGUAGES_BIDI
  1286. ``LANGUAGES_BIDI``
  1287. ------------------
  1288. Default: A list of all language codes that are written right-to-left. You can
  1289. see the current list of these languages by looking in
  1290. :source:`django/conf/global_settings.py`.
  1291. The list contains :term:`language codes<language code>` for languages that are
  1292. written right-to-left.
  1293. Generally, the default value should suffice. Only set this setting if you want
  1294. to restrict language selection to a subset of the Django-provided languages.
  1295. If you define a custom :setting:`LANGUAGES` setting, the list of bidirectional
  1296. languages may contain language codes which are not enabled on a given site.
  1297. .. setting:: LOCALE_PATHS
  1298. ``LOCALE_PATHS``
  1299. ----------------
  1300. Default: ``[]`` (Empty list)
  1301. A list of directories where Django looks for translation files.
  1302. See :ref:`how-django-discovers-translations`.
  1303. Example::
  1304. LOCALE_PATHS = [
  1305. '/home/www/project/common_files/locale',
  1306. '/var/local/translations/locale',
  1307. ]
  1308. Django will look within each of these paths for the ``<locale_code>/LC_MESSAGES``
  1309. directories containing the actual translation files.
  1310. .. setting:: LOGGING
  1311. ``LOGGING``
  1312. -----------
  1313. Default: A logging configuration dictionary.
  1314. A data structure containing configuration information. The contents of
  1315. this data structure will be passed as the argument to the
  1316. configuration method described in :setting:`LOGGING_CONFIG`.
  1317. Among other things, the default logging configuration passes HTTP 500 server
  1318. errors to an email log handler when :setting:`DEBUG` is ``False``. See also
  1319. :ref:`configuring-logging`.
  1320. You can see the default logging configuration by looking in
  1321. :source:`django/utils/log.py`.
  1322. .. setting:: LOGGING_CONFIG
  1323. ``LOGGING_CONFIG``
  1324. ------------------
  1325. Default: ``'logging.config.dictConfig'``
  1326. A path to a callable that will be used to configure logging in the
  1327. Django project. Points at an instance of Python's :ref:`dictConfig
  1328. <logging-config-dictschema>` configuration method by default.
  1329. If you set :setting:`LOGGING_CONFIG` to ``None``, the logging
  1330. configuration process will be skipped.
  1331. .. setting:: MANAGERS
  1332. ``MANAGERS``
  1333. ------------
  1334. Default: ``[]`` (Empty list)
  1335. A list in the same format as :setting:`ADMINS` that specifies who should get
  1336. broken link notifications when
  1337. :class:`~django.middleware.common.BrokenLinkEmailsMiddleware` is enabled.
  1338. .. setting:: MEDIA_ROOT
  1339. ``MEDIA_ROOT``
  1340. --------------
  1341. Default: ``''`` (Empty string)
  1342. Absolute filesystem path to the directory that will hold :doc:`user-uploaded
  1343. files </topics/files>`.
  1344. Example: ``"/var/www/example.com/media/"``
  1345. See also :setting:`MEDIA_URL`.
  1346. .. warning::
  1347. :setting:`MEDIA_ROOT` and :setting:`STATIC_ROOT` must have different
  1348. values. Before :setting:`STATIC_ROOT` was introduced, it was common to
  1349. rely or fallback on :setting:`MEDIA_ROOT` to also serve static files;
  1350. however, since this can have serious security implications, there is a
  1351. validation check to prevent it.
  1352. .. setting:: MEDIA_URL
  1353. ``MEDIA_URL``
  1354. -------------
  1355. Default: ``''`` (Empty string)
  1356. URL that handles the media served from :setting:`MEDIA_ROOT`, used
  1357. for :doc:`managing stored files </topics/files>`. It must end in a slash if set
  1358. to a non-empty value. You will need to :ref:`configure these files to be served
  1359. <serving-uploaded-files-in-development>` in both development and production
  1360. environments.
  1361. If you want to use ``{{ MEDIA_URL }}`` in your templates, add
  1362. ``'django.template.context_processors.media'`` in the ``'context_processors'``
  1363. option of :setting:`TEMPLATES`.
  1364. Example: ``"http://media.example.com/"``
  1365. .. warning::
  1366. There are security risks if you are accepting uploaded content from
  1367. untrusted users! See the security guide's topic on
  1368. :ref:`user-uploaded-content-security` for mitigation details.
  1369. .. warning::
  1370. :setting:`MEDIA_URL` and :setting:`STATIC_URL` must have different
  1371. values. See :setting:`MEDIA_ROOT` for more details.
  1372. .. note::
  1373. If :setting:`MEDIA_URL` is a relative path, then it will be prefixed by the
  1374. server-provided value of ``SCRIPT_NAME`` (or ``/`` if not set). This makes
  1375. it easier to serve a Django application in a subpath without adding an
  1376. extra configuration to the settings.
  1377. .. setting:: MIDDLEWARE
  1378. ``MIDDLEWARE``
  1379. --------------
  1380. Default: ``None``
  1381. A list of middleware to use. See :doc:`/topics/http/middleware`.
  1382. .. setting:: MIGRATION_MODULES
  1383. ``MIGRATION_MODULES``
  1384. ---------------------
  1385. Default: ``{}`` (Empty dictionary)
  1386. A dictionary specifying the package where migration modules can be found on a
  1387. per-app basis. The default value of this setting is an empty dictionary, but
  1388. the default package name for migration modules is ``migrations``.
  1389. Example::
  1390. {'blog': 'blog.db_migrations'}
  1391. In this case, migrations pertaining to the ``blog`` app will be contained in
  1392. the ``blog.db_migrations`` package.
  1393. If you provide the ``app_label`` argument, :djadmin:`makemigrations` will
  1394. automatically create the package if it doesn't already exist.
  1395. When you supply ``None`` as a value for an app, Django will consider the app as
  1396. an app without migrations regardless of an existing ``migrations`` submodule.
  1397. This can be used, for example, in a test settings file to skip migrations while
  1398. testing (tables will still be created for the apps' models). To disable
  1399. migrations for all apps during tests, you can set the
  1400. :setting:`MIGRATE <TEST_MIGRATE>` to ``False`` instead. If
  1401. ``MIGRATION_MODULES`` is used in your general project settings, remember to use
  1402. the :option:`migrate --run-syncdb` option if you want to create tables for the
  1403. app.
  1404. .. setting:: MONTH_DAY_FORMAT
  1405. ``MONTH_DAY_FORMAT``
  1406. --------------------
  1407. Default: ``'F j'``
  1408. The default formatting to use for date fields on Django admin change-list
  1409. pages -- and, possibly, by other parts of the system -- in cases when only the
  1410. month and day are displayed.
  1411. For example, when a Django admin change-list page is being filtered by a date
  1412. drilldown, the header for a given day displays the day and month. Different
  1413. locales have different formats. For example, U.S. English would say
  1414. "January 1," whereas Spanish might say "1 Enero."
  1415. Note that if :setting:`USE_L10N` is set to ``True``, then the corresponding
  1416. locale-dictated format has higher precedence and will be applied.
  1417. See :tfilter:`allowed date format strings <date>`. See also
  1418. :setting:`DATE_FORMAT`, :setting:`DATETIME_FORMAT`,
  1419. :setting:`TIME_FORMAT` and :setting:`YEAR_MONTH_FORMAT`.
  1420. .. setting:: NUMBER_GROUPING
  1421. ``NUMBER_GROUPING``
  1422. -------------------
  1423. Default: ``0``
  1424. Number of digits grouped together on the integer part of a number.
  1425. Common use is to display a thousand separator. If this setting is ``0``, then
  1426. no grouping will be applied to the number. If this setting is greater than
  1427. ``0``, then :setting:`THOUSAND_SEPARATOR` will be used as the separator between
  1428. those groups.
  1429. Some locales use non-uniform digit grouping, e.g. ``10,00,00,000`` in
  1430. ``en_IN``. For this case, you can provide a sequence with the number of digit
  1431. group sizes to be applied. The first number defines the size of the group
  1432. preceding the decimal delimiter, and each number that follows defines the size
  1433. of preceding groups. If the sequence is terminated with ``-1``, no further
  1434. grouping is performed. If the sequence terminates with a ``0``, the last group
  1435. size is used for the remainder of the number.
  1436. Example tuple for ``en_IN``::
  1437. NUMBER_GROUPING = (3, 2, 0)
  1438. Note that if :setting:`USE_L10N` is set to ``True``, then the locale-dictated
  1439. format has higher precedence and will be applied instead.
  1440. See also :setting:`DECIMAL_SEPARATOR`, :setting:`THOUSAND_SEPARATOR` and
  1441. :setting:`USE_THOUSAND_SEPARATOR`.
  1442. .. setting:: PREPEND_WWW
  1443. ``PREPEND_WWW``
  1444. ---------------
  1445. Default: ``False``
  1446. Whether to prepend the "www." subdomain to URLs that don't have it. This is only
  1447. used if :class:`~django.middleware.common.CommonMiddleware` is installed
  1448. (see :doc:`/topics/http/middleware`). See also :setting:`APPEND_SLASH`.
  1449. .. setting:: ROOT_URLCONF
  1450. ``ROOT_URLCONF``
  1451. ----------------
  1452. Default: Not defined
  1453. A string representing the full Python import path to your root URLconf, for
  1454. example ``"mydjangoapps.urls"``. Can be overridden on a per-request basis by
  1455. setting the attribute ``urlconf`` on the incoming ``HttpRequest``
  1456. object. See :ref:`how-django-processes-a-request` for details.
  1457. .. setting:: SECRET_KEY
  1458. ``SECRET_KEY``
  1459. --------------
  1460. Default: ``''`` (Empty string)
  1461. A secret key for a particular Django installation. This is used to provide
  1462. :doc:`cryptographic signing </topics/signing>`, and should be set to a unique,
  1463. unpredictable value.
  1464. :djadmin:`django-admin startproject <startproject>` automatically adds a
  1465. randomly-generated ``SECRET_KEY`` to each new project.
  1466. Uses of the key shouldn't assume that it's text or bytes. Every use should go
  1467. through :func:`~django.utils.encoding.force_str` or
  1468. :func:`~django.utils.encoding.force_bytes` to convert it to the desired type.
  1469. Django will refuse to start if :setting:`SECRET_KEY` is not set.
  1470. .. warning::
  1471. **Keep this value secret.**
  1472. Running Django with a known :setting:`SECRET_KEY` defeats many of Django's
  1473. security protections, and can lead to privilege escalation and remote code
  1474. execution vulnerabilities.
  1475. The secret key is used for:
  1476. * All :doc:`sessions </topics/http/sessions>` if you are using
  1477. any other session backend than ``django.contrib.sessions.backends.cache``,
  1478. or are using the default
  1479. :meth:`~django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash()`.
  1480. * All :doc:`messages </ref/contrib/messages>` if you are using
  1481. :class:`~django.contrib.messages.storage.cookie.CookieStorage` or
  1482. :class:`~django.contrib.messages.storage.fallback.FallbackStorage`.
  1483. * All :class:`~django.contrib.auth.views.PasswordResetView` tokens.
  1484. * Any usage of :doc:`cryptographic signing </topics/signing>`, unless a
  1485. different key is provided.
  1486. If you rotate your secret key, all of the above will be invalidated.
  1487. Secret keys are not used for passwords of users and key rotation will not
  1488. affect them.
  1489. .. note::
  1490. The default :file:`settings.py` file created by :djadmin:`django-admin
  1491. startproject <startproject>` creates a unique ``SECRET_KEY`` for
  1492. convenience.
  1493. .. setting:: SECURE_BROWSER_XSS_FILTER
  1494. ``SECURE_BROWSER_XSS_FILTER``
  1495. -----------------------------
  1496. Default: ``False``
  1497. If ``True``, the :class:`~django.middleware.security.SecurityMiddleware` sets
  1498. the :ref:`x-xss-protection` header on all responses that do not already have it.
  1499. Modern browsers don't honor ``X-XSS-Protection`` HTTP header anymore. Although
  1500. the setting offers little practical benefit, you may still want to set the
  1501. header if you support older browsers.
  1502. .. setting:: SECURE_CONTENT_TYPE_NOSNIFF
  1503. ``SECURE_CONTENT_TYPE_NOSNIFF``
  1504. -------------------------------
  1505. Default: ``True``
  1506. If ``True``, the :class:`~django.middleware.security.SecurityMiddleware`
  1507. sets the :ref:`x-content-type-options` header on all responses that do not
  1508. already have it.
  1509. .. setting:: SECURE_HSTS_INCLUDE_SUBDOMAINS
  1510. ``SECURE_HSTS_INCLUDE_SUBDOMAINS``
  1511. ----------------------------------
  1512. Default: ``False``
  1513. If ``True``, the :class:`~django.middleware.security.SecurityMiddleware` adds
  1514. the ``includeSubDomains`` directive to the :ref:`http-strict-transport-security`
  1515. header. It has no effect unless :setting:`SECURE_HSTS_SECONDS` is set to a
  1516. non-zero value.
  1517. .. warning::
  1518. Setting this incorrectly can irreversibly (for the value of
  1519. :setting:`SECURE_HSTS_SECONDS`) break your site. Read the
  1520. :ref:`http-strict-transport-security` documentation first.
  1521. .. setting:: SECURE_HSTS_PRELOAD
  1522. ``SECURE_HSTS_PRELOAD``
  1523. -----------------------
  1524. Default: ``False``
  1525. If ``True``, the :class:`~django.middleware.security.SecurityMiddleware` adds
  1526. the ``preload`` directive to the :ref:`http-strict-transport-security`
  1527. header. It has no effect unless :setting:`SECURE_HSTS_SECONDS` is set to a
  1528. non-zero value.
  1529. .. setting:: SECURE_HSTS_SECONDS
  1530. ``SECURE_HSTS_SECONDS``
  1531. -----------------------
  1532. Default: ``0``
  1533. If set to a non-zero integer value, the
  1534. :class:`~django.middleware.security.SecurityMiddleware` sets the
  1535. :ref:`http-strict-transport-security` header on all responses that do not
  1536. already have it.
  1537. .. warning::
  1538. Setting this incorrectly can irreversibly (for some time) break your site.
  1539. Read the :ref:`http-strict-transport-security` documentation first.
  1540. .. setting:: SECURE_PROXY_SSL_HEADER
  1541. ``SECURE_PROXY_SSL_HEADER``
  1542. ---------------------------
  1543. Default: ``None``
  1544. A tuple representing a HTTP header/value combination that signifies a request
  1545. is secure. This controls the behavior of the request object's ``is_secure()``
  1546. method.
  1547. By default, ``is_secure()`` determines if a request is secure by confirming
  1548. that a requested URL uses ``https://``. This method is important for Django's
  1549. CSRF protection, and it may be used by your own code or third-party apps.
  1550. If your Django app is behind a proxy, though, the proxy may be "swallowing"
  1551. whether the original request uses HTTPS or not. If there is a non-HTTPS
  1552. connection between the proxy and Django then ``is_secure()`` would always
  1553. return ``False`` -- even for requests that were made via HTTPS by the end user.
  1554. In contrast, if there is an HTTPS connection between the proxy and Django then
  1555. ``is_secure()`` would always return ``True`` -- even for requests that were
  1556. made originally via HTTP.
  1557. In this situation, configure your proxy to set a custom HTTP header that tells
  1558. Django whether the request came in via HTTPS, and set
  1559. ``SECURE_PROXY_SSL_HEADER`` so that Django knows what header to look for.
  1560. Set a tuple with two elements -- the name of the header to look for and the
  1561. required value. For example::
  1562. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
  1563. This tells Django to trust the ``X-Forwarded-Proto`` header that comes from our
  1564. proxy, and any time its value is ``'https'``, then the request is guaranteed to
  1565. be secure (i.e., it originally came in via HTTPS).
  1566. You should *only* set this setting if you control your proxy or have some other
  1567. guarantee that it sets/strips this header appropriately.
  1568. Note that the header needs to be in the format as used by ``request.META`` --
  1569. all caps and likely starting with ``HTTP_``. (Remember, Django automatically
  1570. adds ``'HTTP_'`` to the start of x-header names before making the header
  1571. available in ``request.META``.)
  1572. .. warning::
  1573. **Modifying this setting can compromise your site's security. Ensure you
  1574. fully understand your setup before changing it.**
  1575. Make sure ALL of the following are true before setting this (assuming the
  1576. values from the example above):
  1577. * Your Django app is behind a proxy.
  1578. * Your proxy strips the ``X-Forwarded-Proto`` header from all incoming
  1579. requests. In other words, if end users include that header in their
  1580. requests, the proxy will discard it.
  1581. * Your proxy sets the ``X-Forwarded-Proto`` header and sends it to Django,
  1582. but only for requests that originally come in via HTTPS.
  1583. If any of those are not true, you should keep this setting set to ``None``
  1584. and find another way of determining HTTPS, perhaps via custom middleware.
  1585. .. setting:: SECURE_REDIRECT_EXEMPT
  1586. ``SECURE_REDIRECT_EXEMPT``
  1587. --------------------------
  1588. Default: ``[]`` (Empty list)
  1589. If a URL path matches a regular expression in this list, the request will not be
  1590. redirected to HTTPS. The
  1591. :class:`~django.middleware.security.SecurityMiddleware` strips leading slashes
  1592. from URL paths, so patterns shouldn't include them, e.g.
  1593. ``SECURE_REDIRECT_EXEMPT = [r'^no-ssl/$', …]``. If
  1594. :setting:`SECURE_SSL_REDIRECT` is ``False``, this setting has no effect.
  1595. .. setting:: SECURE_REFERRER_POLICY
  1596. ``SECURE_REFERRER_POLICY``
  1597. --------------------------
  1598. Default: ``'same-origin'``
  1599. If configured, the :class:`~django.middleware.security.SecurityMiddleware` sets
  1600. the :ref:`referrer-policy` header on all responses that do not already have it
  1601. to the value provided.
  1602. .. versionchanged:: 3.1
  1603. In older versions, the default value is ``None``.
  1604. .. setting:: SECURE_SSL_HOST
  1605. ``SECURE_SSL_HOST``
  1606. -------------------
  1607. Default: ``None``
  1608. If a string (e.g. ``secure.example.com``), all SSL redirects will be directed
  1609. to this host rather than the originally-requested host
  1610. (e.g. ``www.example.com``). If :setting:`SECURE_SSL_REDIRECT` is ``False``, this
  1611. setting has no effect.
  1612. .. setting:: SECURE_SSL_REDIRECT
  1613. ``SECURE_SSL_REDIRECT``
  1614. -----------------------
  1615. Default: ``False``
  1616. If ``True``, the :class:`~django.middleware.security.SecurityMiddleware`
  1617. :ref:`redirects <ssl-redirect>` all non-HTTPS requests to HTTPS (except for
  1618. those URLs matching a regular expression listed in
  1619. :setting:`SECURE_REDIRECT_EXEMPT`).
  1620. .. note::
  1621. If turning this to ``True`` causes infinite redirects, it probably means
  1622. your site is running behind a proxy and can't tell which requests are secure
  1623. and which are not. Your proxy likely sets a header to indicate secure
  1624. requests; you can correct the problem by finding out what that header is and
  1625. configuring the :setting:`SECURE_PROXY_SSL_HEADER` setting accordingly.
  1626. .. setting:: SERIALIZATION_MODULES
  1627. ``SERIALIZATION_MODULES``
  1628. -------------------------
  1629. Default: Not defined
  1630. A dictionary of modules containing serializer definitions (provided as
  1631. strings), keyed by a string identifier for that serialization type. For
  1632. example, to define a YAML serializer, use::
  1633. SERIALIZATION_MODULES = {'yaml': 'path.to.yaml_serializer'}
  1634. .. setting:: SERVER_EMAIL
  1635. ``SERVER_EMAIL``
  1636. ----------------
  1637. Default: ``'root@localhost'``
  1638. The email address that error messages come from, such as those sent to
  1639. :setting:`ADMINS` and :setting:`MANAGERS`.
  1640. .. admonition:: Why are my emails sent from a different address?
  1641. This address is used only for error messages. It is *not* the address that
  1642. regular email messages sent with :meth:`~django.core.mail.send_mail()`
  1643. come from; for that, see :setting:`DEFAULT_FROM_EMAIL`.
  1644. .. setting:: SHORT_DATE_FORMAT
  1645. ``SHORT_DATE_FORMAT``
  1646. ---------------------
  1647. Default: ``'m/d/Y'`` (e.g. ``12/31/2003``)
  1648. An available formatting that can be used for displaying date fields on
  1649. templates. Note that if :setting:`USE_L10N` is set to ``True``, then the
  1650. corresponding locale-dictated format has higher precedence and will be applied.
  1651. See :tfilter:`allowed date format strings <date>`.
  1652. See also :setting:`DATE_FORMAT` and :setting:`SHORT_DATETIME_FORMAT`.
  1653. .. setting:: SHORT_DATETIME_FORMAT
  1654. ``SHORT_DATETIME_FORMAT``
  1655. -------------------------
  1656. Default: ``'m/d/Y P'`` (e.g. ``12/31/2003 4 p.m.``)
  1657. An available formatting that can be used for displaying datetime fields on
  1658. templates. Note that if :setting:`USE_L10N` is set to ``True``, then the
  1659. corresponding locale-dictated format has higher precedence and will be applied.
  1660. See :tfilter:`allowed date format strings <date>`.
  1661. See also :setting:`DATE_FORMAT` and :setting:`SHORT_DATE_FORMAT`.
  1662. .. setting:: SIGNING_BACKEND
  1663. ``SIGNING_BACKEND``
  1664. -------------------
  1665. Default: ``'django.core.signing.TimestampSigner'``
  1666. The backend used for signing cookies and other data.
  1667. See also the :doc:`/topics/signing` documentation.
  1668. .. setting:: SILENCED_SYSTEM_CHECKS
  1669. ``SILENCED_SYSTEM_CHECKS``
  1670. --------------------------
  1671. Default: ``[]`` (Empty list)
  1672. A list of identifiers of messages generated by the system check framework
  1673. (i.e. ``["models.W001"]``) that you wish to permanently acknowledge and ignore.
  1674. Silenced checks will not be output to the console.
  1675. See also the :doc:`/ref/checks` documentation.
  1676. .. setting:: TEMPLATES
  1677. ``TEMPLATES``
  1678. -------------
  1679. Default: ``[]`` (Empty list)
  1680. A list containing the settings for all template engines to be used with
  1681. Django. Each item of the list is a dictionary containing the options for an
  1682. individual engine.
  1683. Here's a setup that tells the Django template engine to load templates from the
  1684. ``templates`` subdirectory inside each installed application::
  1685. TEMPLATES = [
  1686. {
  1687. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  1688. 'APP_DIRS': True,
  1689. },
  1690. ]
  1691. The following options are available for all backends.
  1692. .. setting:: TEMPLATES-BACKEND
  1693. ``BACKEND``
  1694. ~~~~~~~~~~~
  1695. Default: Not defined
  1696. The template backend to use. The built-in template backends are:
  1697. * ``'django.template.backends.django.DjangoTemplates'``
  1698. * ``'django.template.backends.jinja2.Jinja2'``
  1699. You can use a template backend that doesn't ship with Django by setting
  1700. ``BACKEND`` to a fully-qualified path (i.e. ``'mypackage.whatever.Backend'``).
  1701. .. setting:: TEMPLATES-NAME
  1702. ``NAME``
  1703. ~~~~~~~~
  1704. Default: see below
  1705. The alias for this particular template engine. It's an identifier that allows
  1706. selecting an engine for rendering. Aliases must be unique across all
  1707. configured template engines.
  1708. It defaults to the name of the module defining the engine class, i.e. the
  1709. next to last piece of :setting:`BACKEND <TEMPLATES-BACKEND>`, when it isn't
  1710. provided. For example if the backend is ``'mypackage.whatever.Backend'`` then
  1711. its default name is ``'whatever'``.
  1712. .. setting:: TEMPLATES-DIRS
  1713. ``DIRS``
  1714. ~~~~~~~~
  1715. Default: ``[]`` (Empty list)
  1716. Directories where the engine should look for template source files, in search
  1717. order.
  1718. .. setting:: TEMPLATES-APP_DIRS
  1719. ``APP_DIRS``
  1720. ~~~~~~~~~~~~
  1721. Default: ``False``
  1722. Whether the engine should look for template source files inside installed
  1723. applications.
  1724. .. note::
  1725. The default :file:`settings.py` file created by :djadmin:`django-admin
  1726. startproject <startproject>` sets ``'APP_DIRS': True``.
  1727. .. setting:: TEMPLATES-OPTIONS
  1728. ``OPTIONS``
  1729. ~~~~~~~~~~~
  1730. Default: ``{}`` (Empty dict)
  1731. Extra parameters to pass to the template backend. Available parameters vary
  1732. depending on the template backend. See
  1733. :class:`~django.template.backends.django.DjangoTemplates` and
  1734. :class:`~django.template.backends.jinja2.Jinja2` for the options of the
  1735. built-in backends.
  1736. .. setting:: TEST_RUNNER
  1737. ``TEST_RUNNER``
  1738. ---------------
  1739. Default: ``'django.test.runner.DiscoverRunner'``
  1740. The name of the class to use for starting the test suite. See
  1741. :ref:`other-testing-frameworks`.
  1742. .. setting:: TEST_NON_SERIALIZED_APPS
  1743. ``TEST_NON_SERIALIZED_APPS``
  1744. ----------------------------
  1745. Default: ``[]`` (Empty list)
  1746. In order to restore the database state between tests for
  1747. ``TransactionTestCase``\s and database backends without transactions, Django
  1748. will :ref:`serialize the contents of all apps <test-case-serialized-rollback>`
  1749. when it starts the test run so it can then reload from that copy before running
  1750. tests that need it.
  1751. This slows down the startup time of the test runner; if you have apps that
  1752. you know don't need this feature, you can add their full names in here (e.g.
  1753. ``'django.contrib.contenttypes'``) to exclude them from this serialization
  1754. process.
  1755. .. setting:: THOUSAND_SEPARATOR
  1756. ``THOUSAND_SEPARATOR``
  1757. ----------------------
  1758. Default: ``','`` (Comma)
  1759. Default thousand separator used when formatting numbers. This setting is
  1760. used only when :setting:`USE_THOUSAND_SEPARATOR` is ``True`` and
  1761. :setting:`NUMBER_GROUPING` is greater than ``0``.
  1762. Note that if :setting:`USE_L10N` is set to ``True``, then the locale-dictated
  1763. format has higher precedence and will be applied instead.
  1764. See also :setting:`NUMBER_GROUPING`, :setting:`DECIMAL_SEPARATOR` and
  1765. :setting:`USE_THOUSAND_SEPARATOR`.
  1766. .. setting:: TIME_FORMAT
  1767. ``TIME_FORMAT``
  1768. ---------------
  1769. Default: ``'P'`` (e.g. ``4 p.m.``)
  1770. The default formatting to use for displaying time fields in any part of the
  1771. system. Note that if :setting:`USE_L10N` is set to ``True``, then the
  1772. locale-dictated format has higher precedence and will be applied instead. See
  1773. :tfilter:`allowed date format strings <date>`.
  1774. See also :setting:`DATE_FORMAT` and :setting:`DATETIME_FORMAT`.
  1775. .. setting:: TIME_INPUT_FORMATS
  1776. ``TIME_INPUT_FORMATS``
  1777. ----------------------
  1778. Default::
  1779. [
  1780. '%H:%M:%S', # '14:30:59'
  1781. '%H:%M:%S.%f', # '14:30:59.000200'
  1782. '%H:%M', # '14:30'
  1783. ]
  1784. A list of formats that will be accepted when inputting data on a time field.
  1785. Formats will be tried in order, using the first valid one. Note that these
  1786. format strings use Python's :ref:`datetime module syntax
  1787. <strftime-strptime-behavior>`, not the format strings from the :tfilter:`date`
  1788. template filter.
  1789. When :setting:`USE_L10N` is ``True``, the locale-dictated format has higher
  1790. precedence and will be applied instead.
  1791. See also :setting:`DATE_INPUT_FORMATS` and :setting:`DATETIME_INPUT_FORMATS`.
  1792. .. setting:: TIME_ZONE
  1793. ``TIME_ZONE``
  1794. -------------
  1795. Default: ``'America/Chicago'``
  1796. A string representing the time zone for this installation. See the `list of
  1797. time zones`_.
  1798. .. note::
  1799. Since Django was first released with the :setting:`TIME_ZONE` set to
  1800. ``'America/Chicago'``, the global setting (used if nothing is defined in
  1801. your project's ``settings.py``) remains ``'America/Chicago'`` for backwards
  1802. compatibility. New project templates default to ``'UTC'``.
  1803. Note that this isn't necessarily the time zone of the server. For example, one
  1804. server may serve multiple Django-powered sites, each with a separate time zone
  1805. setting.
  1806. When :setting:`USE_TZ` is ``False``, this is the time zone in which Django
  1807. will store all datetimes. When :setting:`USE_TZ` is ``True``, this is the
  1808. default time zone that Django will use to display datetimes in templates and
  1809. to interpret datetimes entered in forms.
  1810. On Unix environments (where :func:`time.tzset` is implemented), Django sets the
  1811. ``os.environ['TZ']`` variable to the time zone you specify in the
  1812. :setting:`TIME_ZONE` setting. Thus, all your views and models will
  1813. automatically operate in this time zone. However, Django won't set the ``TZ``
  1814. environment variable if you're using the manual configuration option as
  1815. described in :ref:`manually configuring settings
  1816. <settings-without-django-settings-module>`. If Django doesn't set the ``TZ``
  1817. environment variable, it's up to you to ensure your processes are running in
  1818. the correct environment.
  1819. .. note::
  1820. Django cannot reliably use alternate time zones in a Windows environment.
  1821. If you're running Django on Windows, :setting:`TIME_ZONE` must be set to
  1822. match the system time zone.
  1823. .. _list of time zones: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  1824. .. setting:: USE_I18N
  1825. ``USE_I18N``
  1826. ------------
  1827. Default: ``True``
  1828. A boolean that specifies whether Django's translation system should be enabled.
  1829. This provides a way to turn it off, for performance. If this is set to
  1830. ``False``, Django will make some optimizations so as not to load the
  1831. translation machinery.
  1832. See also :setting:`LANGUAGE_CODE`, :setting:`USE_L10N` and :setting:`USE_TZ`.
  1833. .. note::
  1834. The default :file:`settings.py` file created by :djadmin:`django-admin
  1835. startproject <startproject>` includes ``USE_I18N = True`` for convenience.
  1836. .. setting:: USE_L10N
  1837. ``USE_L10N``
  1838. ------------
  1839. Default: ``False``
  1840. A boolean that specifies if localized formatting of data will be enabled by
  1841. default or not. If this is set to ``True``, e.g. Django will display numbers and
  1842. dates using the format of the current locale.
  1843. See also :setting:`LANGUAGE_CODE`, :setting:`USE_I18N` and :setting:`USE_TZ`.
  1844. .. note::
  1845. The default :file:`settings.py` file created by :djadmin:`django-admin
  1846. startproject <startproject>` includes ``USE_L10N = True`` for convenience.
  1847. .. setting:: USE_THOUSAND_SEPARATOR
  1848. ``USE_THOUSAND_SEPARATOR``
  1849. --------------------------
  1850. Default: ``False``
  1851. A boolean that specifies whether to display numbers using a thousand separator.
  1852. When set to ``True`` and :setting:`USE_L10N` is also ``True``, Django will
  1853. format numbers using the :setting:`NUMBER_GROUPING` and
  1854. :setting:`THOUSAND_SEPARATOR` settings. These settings may also be dictated by
  1855. the locale, which takes precedence.
  1856. See also :setting:`DECIMAL_SEPARATOR`, :setting:`NUMBER_GROUPING` and
  1857. :setting:`THOUSAND_SEPARATOR`.
  1858. .. setting:: USE_TZ
  1859. ``USE_TZ``
  1860. ----------
  1861. Default: ``False``
  1862. A boolean that specifies if datetimes will be timezone-aware by default or not.
  1863. If this is set to ``True``, Django will use timezone-aware datetimes internally.
  1864. When ``USE_TZ`` is False, Django will use naive datetimes in local time, except
  1865. when parsing ISO 8601 formatted strings, where timezone information will always
  1866. be retained if present.
  1867. See also :setting:`TIME_ZONE`, :setting:`USE_I18N` and :setting:`USE_L10N`.
  1868. .. note::
  1869. The default :file:`settings.py` file created by
  1870. :djadmin:`django-admin startproject <startproject>` includes
  1871. ``USE_TZ = True`` for convenience.
  1872. .. setting:: USE_X_FORWARDED_HOST
  1873. ``USE_X_FORWARDED_HOST``
  1874. ------------------------
  1875. Default: ``False``
  1876. A boolean that specifies whether to use the ``X-Forwarded-Host`` header in
  1877. preference to the ``Host`` header. This should only be enabled if a proxy
  1878. which sets this header is in use.
  1879. This setting takes priority over :setting:`USE_X_FORWARDED_PORT`. Per
  1880. :rfc:`7239#section-5.3`, the ``X-Forwarded-Host`` header can include the port
  1881. number, in which case you shouldn't use :setting:`USE_X_FORWARDED_PORT`.
  1882. .. setting:: USE_X_FORWARDED_PORT
  1883. ``USE_X_FORWARDED_PORT``
  1884. ------------------------
  1885. Default: ``False``
  1886. A boolean that specifies whether to use the ``X-Forwarded-Port`` header in
  1887. preference to the ``SERVER_PORT`` ``META`` variable. This should only be
  1888. enabled if a proxy which sets this header is in use.
  1889. :setting:`USE_X_FORWARDED_HOST` takes priority over this setting.
  1890. .. setting:: WSGI_APPLICATION
  1891. ``WSGI_APPLICATION``
  1892. --------------------
  1893. Default: ``None``
  1894. The full Python path of the WSGI application object that Django's built-in
  1895. servers (e.g. :djadmin:`runserver`) will use. The :djadmin:`django-admin
  1896. startproject <startproject>` management command will create a standard
  1897. ``wsgi.py`` file with an ``application`` callable in it, and point this setting
  1898. to that ``application``.
  1899. If not set, the return value of ``django.core.wsgi.get_wsgi_application()``
  1900. will be used. In this case, the behavior of :djadmin:`runserver` will be
  1901. identical to previous Django versions.
  1902. .. setting:: YEAR_MONTH_FORMAT
  1903. ``YEAR_MONTH_FORMAT``
  1904. ---------------------
  1905. Default: ``'F Y'``
  1906. The default formatting to use for date fields on Django admin change-list
  1907. pages -- and, possibly, by other parts of the system -- in cases when only the
  1908. year and month are displayed.
  1909. For example, when a Django admin change-list page is being filtered by a date
  1910. drilldown, the header for a given month displays the month and the year.
  1911. Different locales have different formats. For example, U.S. English would say
  1912. "January 2006," whereas another locale might say "2006/January."
  1913. Note that if :setting:`USE_L10N` is set to ``True``, then the corresponding
  1914. locale-dictated format has higher precedence and will be applied.
  1915. See :tfilter:`allowed date format strings <date>`. See also
  1916. :setting:`DATE_FORMAT`, :setting:`DATETIME_FORMAT`, :setting:`TIME_FORMAT`
  1917. and :setting:`MONTH_DAY_FORMAT`.
  1918. .. setting:: X_FRAME_OPTIONS
  1919. ``X_FRAME_OPTIONS``
  1920. -------------------
  1921. Default: ``'DENY'``
  1922. The default value for the X-Frame-Options header used by
  1923. :class:`~django.middleware.clickjacking.XFrameOptionsMiddleware`. See the
  1924. :doc:`clickjacking protection </ref/clickjacking/>` documentation.
  1925. Auth
  1926. ====
  1927. Settings for :mod:`django.contrib.auth`.
  1928. .. setting:: AUTHENTICATION_BACKENDS
  1929. ``AUTHENTICATION_BACKENDS``
  1930. ---------------------------
  1931. Default: ``['django.contrib.auth.backends.ModelBackend']``
  1932. A list of authentication backend classes (as strings) to use when attempting to
  1933. authenticate a user. See the :ref:`authentication backends documentation
  1934. <authentication-backends>` for details.
  1935. .. setting:: AUTH_USER_MODEL
  1936. ``AUTH_USER_MODEL``
  1937. -------------------
  1938. Default: ``'auth.User'``
  1939. The model to use to represent a User. See :ref:`auth-custom-user`.
  1940. .. warning::
  1941. You cannot change the AUTH_USER_MODEL setting during the lifetime of
  1942. a project (i.e. once you have made and migrated models that depend on it)
  1943. without serious effort. It is intended to be set at the project start,
  1944. and the model it refers to must be available in the first migration of
  1945. the app that it lives in.
  1946. See :ref:`auth-custom-user` for more details.
  1947. .. setting:: LOGIN_REDIRECT_URL
  1948. ``LOGIN_REDIRECT_URL``
  1949. ----------------------
  1950. Default: ``'/accounts/profile/'``
  1951. The URL or :ref:`named URL pattern <naming-url-patterns>` where requests are
  1952. redirected after login when the :class:`~django.contrib.auth.views.LoginView`
  1953. doesn't get a ``next`` GET parameter.
  1954. .. setting:: LOGIN_URL
  1955. ``LOGIN_URL``
  1956. -------------
  1957. Default: ``'/accounts/login/'``
  1958. The URL or :ref:`named URL pattern <naming-url-patterns>` where requests are
  1959. redirected for login when using the
  1960. :func:`~django.contrib.auth.decorators.login_required` decorator,
  1961. :class:`~django.contrib.auth.mixins.LoginRequiredMixin`, or
  1962. :class:`~django.contrib.auth.mixins.AccessMixin`.
  1963. .. setting:: LOGOUT_REDIRECT_URL
  1964. ``LOGOUT_REDIRECT_URL``
  1965. -----------------------
  1966. Default: ``None``
  1967. The URL or :ref:`named URL pattern <naming-url-patterns>` where requests are
  1968. redirected after logout if :class:`~django.contrib.auth.views.LogoutView`
  1969. doesn't have a ``next_page`` attribute.
  1970. If ``None``, no redirect will be performed and the logout view will be
  1971. rendered.
  1972. .. setting:: PASSWORD_RESET_TIMEOUT
  1973. ``PASSWORD_RESET_TIMEOUT``
  1974. --------------------------
  1975. .. versionadded:: 3.1
  1976. Default: ``259200`` (3 days, in seconds)
  1977. The number of seconds a password reset link is valid for.
  1978. Used by the :class:`~django.contrib.auth.views.PasswordResetConfirmView`.
  1979. .. note::
  1980. Reducing the value of this timeout doesn't make any difference to the
  1981. ability of an attacker to brute-force a password reset token. Tokens are
  1982. designed to be safe from brute-forcing without any timeout.
  1983. This timeout exists to protect against some unlikely attack scenarios, such
  1984. as someone gaining access to email archives that may contain old, unused
  1985. password reset tokens.
  1986. .. setting:: PASSWORD_RESET_TIMEOUT_DAYS
  1987. ``PASSWORD_RESET_TIMEOUT_DAYS``
  1988. -------------------------------
  1989. Default: ``3``
  1990. The number of days a password reset link is valid for.
  1991. Used by the :class:`~django.contrib.auth.views.PasswordResetConfirmView`.
  1992. .. deprecated:: 3.1
  1993. This setting is deprecated. Use :setting:`PASSWORD_RESET_TIMEOUT` instead.
  1994. .. setting:: PASSWORD_HASHERS
  1995. ``PASSWORD_HASHERS``
  1996. --------------------
  1997. See :ref:`auth_password_storage`.
  1998. Default::
  1999. [
  2000. 'django.contrib.auth.hashers.PBKDF2PasswordHasher',
  2001. 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
  2002. 'django.contrib.auth.hashers.Argon2PasswordHasher',
  2003. 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
  2004. ]
  2005. .. setting:: AUTH_PASSWORD_VALIDATORS
  2006. ``AUTH_PASSWORD_VALIDATORS``
  2007. ----------------------------
  2008. Default: ``[]`` (Empty list)
  2009. The list of validators that are used to check the strength of user's passwords.
  2010. See :ref:`password-validation` for more details. By default, no validation is
  2011. performed and all passwords are accepted.
  2012. .. _settings-messages:
  2013. Messages
  2014. ========
  2015. Settings for :mod:`django.contrib.messages`.
  2016. .. setting:: MESSAGE_LEVEL
  2017. ``MESSAGE_LEVEL``
  2018. -----------------
  2019. Default: ``messages.INFO``
  2020. Sets the minimum message level that will be recorded by the messages
  2021. framework. See :ref:`message levels <message-level>` for more details.
  2022. .. admonition:: Important
  2023. If you override ``MESSAGE_LEVEL`` in your settings file and rely on any of
  2024. the built-in constants, you must import the constants module directly to
  2025. avoid the potential for circular imports, e.g.::
  2026. from django.contrib.messages import constants as message_constants
  2027. MESSAGE_LEVEL = message_constants.DEBUG
  2028. If desired, you may specify the numeric values for the constants directly
  2029. according to the values in the above :ref:`constants table
  2030. <message-level-constants>`.
  2031. .. setting:: MESSAGE_STORAGE
  2032. ``MESSAGE_STORAGE``
  2033. -------------------
  2034. Default: ``'django.contrib.messages.storage.fallback.FallbackStorage'``
  2035. Controls where Django stores message data. Valid values are:
  2036. * ``'django.contrib.messages.storage.fallback.FallbackStorage'``
  2037. * ``'django.contrib.messages.storage.session.SessionStorage'``
  2038. * ``'django.contrib.messages.storage.cookie.CookieStorage'``
  2039. See :ref:`message storage backends <message-storage-backends>` for more details.
  2040. The backends that use cookies --
  2041. :class:`~django.contrib.messages.storage.cookie.CookieStorage` and
  2042. :class:`~django.contrib.messages.storage.fallback.FallbackStorage` --
  2043. use the value of :setting:`SESSION_COOKIE_DOMAIN`, :setting:`SESSION_COOKIE_SECURE`
  2044. and :setting:`SESSION_COOKIE_HTTPONLY` when setting their cookies.
  2045. .. setting:: MESSAGE_TAGS
  2046. ``MESSAGE_TAGS``
  2047. ----------------
  2048. Default::
  2049. {
  2050. messages.DEBUG: 'debug',
  2051. messages.INFO: 'info',
  2052. messages.SUCCESS: 'success',
  2053. messages.WARNING: 'warning',
  2054. messages.ERROR: 'error',
  2055. }
  2056. This sets the mapping of message level to message tag, which is typically
  2057. rendered as a CSS class in HTML. If you specify a value, it will extend
  2058. the default. This means you only have to specify those values which you need
  2059. to override. See :ref:`message-displaying` above for more details.
  2060. .. admonition:: Important
  2061. If you override ``MESSAGE_TAGS`` in your settings file and rely on any of
  2062. the built-in constants, you must import the ``constants`` module directly to
  2063. avoid the potential for circular imports, e.g.::
  2064. from django.contrib.messages import constants as message_constants
  2065. MESSAGE_TAGS = {message_constants.INFO: ''}
  2066. If desired, you may specify the numeric values for the constants directly
  2067. according to the values in the above :ref:`constants table
  2068. <message-level-constants>`.
  2069. .. _settings-sessions:
  2070. Sessions
  2071. ========
  2072. Settings for :mod:`django.contrib.sessions`.
  2073. .. setting:: SESSION_CACHE_ALIAS
  2074. ``SESSION_CACHE_ALIAS``
  2075. -----------------------
  2076. Default: ``'default'``
  2077. If you're using :ref:`cache-based session storage <cached-sessions-backend>`,
  2078. this selects the cache to use.
  2079. .. setting:: SESSION_COOKIE_AGE
  2080. ``SESSION_COOKIE_AGE``
  2081. ----------------------
  2082. Default: ``1209600`` (2 weeks, in seconds)
  2083. The age of session cookies, in seconds.
  2084. .. setting:: SESSION_COOKIE_DOMAIN
  2085. ``SESSION_COOKIE_DOMAIN``
  2086. -------------------------
  2087. Default: ``None``
  2088. The domain to use for session cookies. Set this to a string such as
  2089. ``"example.com"`` for cross-domain cookies, or use ``None`` for a standard
  2090. domain cookie.
  2091. Be cautious when updating this setting on a production site. If you update
  2092. this setting to enable cross-domain cookies on a site that previously used
  2093. standard domain cookies, existing user cookies will be set to the old
  2094. domain. This may result in them being unable to log in as long as these cookies
  2095. persist.
  2096. This setting also affects cookies set by :mod:`django.contrib.messages`.
  2097. .. setting:: SESSION_COOKIE_HTTPONLY
  2098. ``SESSION_COOKIE_HTTPONLY``
  2099. ---------------------------
  2100. Default: ``True``
  2101. Whether to use ``HttpOnly`` flag on the session cookie. If this is set to
  2102. ``True``, client-side JavaScript will not be able to access the session
  2103. cookie.
  2104. HttpOnly_ is a flag included in a Set-Cookie HTTP response header. It's part of
  2105. the :rfc:`6265#section-4.1.2.6` standard for cookies and can be a useful way to
  2106. mitigate the risk of a client-side script accessing the protected cookie data.
  2107. This makes it less trivial for an attacker to escalate a cross-site scripting
  2108. vulnerability into full hijacking of a user's session. There aren't many good
  2109. reasons for turning this off. Your code shouldn't read session cookies from
  2110. JavaScript.
  2111. .. _HttpOnly: https://owasp.org/www-community/HttpOnly
  2112. .. setting:: SESSION_COOKIE_NAME
  2113. ``SESSION_COOKIE_NAME``
  2114. -----------------------
  2115. Default: ``'sessionid'``
  2116. The name of the cookie to use for sessions. This can be whatever you want
  2117. (as long as it's different from the other cookie names in your application).
  2118. .. setting:: SESSION_COOKIE_PATH
  2119. ``SESSION_COOKIE_PATH``
  2120. -----------------------
  2121. Default: ``'/'``
  2122. The path set on the session cookie. This should either match the URL path of your
  2123. Django installation or be parent of that path.
  2124. This is useful if you have multiple Django instances running under the same
  2125. hostname. They can use different cookie paths, and each instance will only see
  2126. its own session cookie.
  2127. .. setting:: SESSION_COOKIE_SAMESITE
  2128. ``SESSION_COOKIE_SAMESITE``
  2129. ---------------------------
  2130. Default: ``'Lax'``
  2131. The value of the `SameSite`_ flag on the session cookie. This flag prevents the
  2132. cookie from being sent in cross-site requests thus preventing CSRF attacks and
  2133. making some methods of stealing session cookie impossible.
  2134. Possible values for the setting are:
  2135. * ``'Strict'``: prevents the cookie from being sent by the browser to the
  2136. target site in all cross-site browsing context, even when following a regular
  2137. link.
  2138. For example, for a GitHub-like website this would mean that if a logged-in
  2139. user follows a link to a private GitHub project posted on a corporate
  2140. discussion forum or email, GitHub will not receive the session cookie and the
  2141. user won't be able to access the project. A bank website, however, most
  2142. likely doesn't want to allow any transactional pages to be linked from
  2143. external sites so the ``'Strict'`` flag would be appropriate.
  2144. * ``'Lax'`` (default): provides a balance between security and usability for
  2145. websites that want to maintain user's logged-in session after the user
  2146. arrives from an external link.
  2147. In the GitHub scenario, the session cookie would be allowed when following a
  2148. regular link from an external website and be blocked in CSRF-prone request
  2149. methods (e.g. ``POST``).
  2150. * ``'None'`` (string): the session cookie will be sent with all same-site and
  2151. cross-site requests.
  2152. * ``False``: disables the flag.
  2153. .. versionchanged:: 3.1
  2154. Setting ``SESSION_COOKIE_SAMESITE = 'None'`` was allowed.
  2155. .. _SameSite: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
  2156. .. setting:: SESSION_COOKIE_SECURE
  2157. ``SESSION_COOKIE_SECURE``
  2158. -------------------------
  2159. Default: ``False``
  2160. Whether to use a secure cookie for the session cookie. If this is set to
  2161. ``True``, the cookie will be marked as "secure", which means browsers may
  2162. ensure that the cookie is only sent under an HTTPS connection.
  2163. Leaving this setting off isn't a good idea because an attacker could capture an
  2164. unencrypted session cookie with a packet sniffer and use the cookie to hijack
  2165. the user's session.
  2166. .. setting:: SESSION_ENGINE
  2167. ``SESSION_ENGINE``
  2168. ------------------
  2169. Default: ``'django.contrib.sessions.backends.db'``
  2170. Controls where Django stores session data. Included engines are:
  2171. * ``'django.contrib.sessions.backends.db'``
  2172. * ``'django.contrib.sessions.backends.file'``
  2173. * ``'django.contrib.sessions.backends.cache'``
  2174. * ``'django.contrib.sessions.backends.cached_db'``
  2175. * ``'django.contrib.sessions.backends.signed_cookies'``
  2176. See :ref:`configuring-sessions` for more details.
  2177. .. setting:: SESSION_EXPIRE_AT_BROWSER_CLOSE
  2178. ``SESSION_EXPIRE_AT_BROWSER_CLOSE``
  2179. -----------------------------------
  2180. Default: ``False``
  2181. Whether to expire the session when the user closes their browser. See
  2182. :ref:`browser-length-vs-persistent-sessions`.
  2183. .. setting:: SESSION_FILE_PATH
  2184. ``SESSION_FILE_PATH``
  2185. ---------------------
  2186. Default: ``None``
  2187. If you're using file-based session storage, this sets the directory in
  2188. which Django will store session data. When the default value (``None``) is
  2189. used, Django will use the standard temporary directory for the system.
  2190. .. setting:: SESSION_SAVE_EVERY_REQUEST
  2191. ``SESSION_SAVE_EVERY_REQUEST``
  2192. ------------------------------
  2193. Default: ``False``
  2194. Whether to save the session data on every request. If this is ``False``
  2195. (default), then the session data will only be saved if it has been modified --
  2196. that is, if any of its dictionary values have been assigned or deleted. Empty
  2197. sessions won't be created, even if this setting is active.
  2198. .. setting:: SESSION_SERIALIZER
  2199. ``SESSION_SERIALIZER``
  2200. ----------------------
  2201. Default: ``'django.contrib.sessions.serializers.JSONSerializer'``
  2202. Full import path of a serializer class to use for serializing session data.
  2203. Included serializers are:
  2204. * ``'django.contrib.sessions.serializers.PickleSerializer'``
  2205. * ``'django.contrib.sessions.serializers.JSONSerializer'``
  2206. See :ref:`session_serialization` for details, including a warning regarding
  2207. possible remote code execution when using
  2208. :class:`~django.contrib.sessions.serializers.PickleSerializer`.
  2209. Sites
  2210. =====
  2211. Settings for :mod:`django.contrib.sites`.
  2212. .. setting:: SITE_ID
  2213. ``SITE_ID``
  2214. -----------
  2215. Default: Not defined
  2216. The ID, as an integer, of the current site in the ``django_site`` database
  2217. table. This is used so that application data can hook into specific sites
  2218. and a single database can manage content for multiple sites.
  2219. .. _settings-staticfiles:
  2220. Static Files
  2221. ============
  2222. Settings for :mod:`django.contrib.staticfiles`.
  2223. .. setting:: STATIC_ROOT
  2224. ``STATIC_ROOT``
  2225. ---------------
  2226. Default: ``None``
  2227. The absolute path to the directory where :djadmin:`collectstatic` will collect
  2228. static files for deployment.
  2229. Example: ``"/var/www/example.com/static/"``
  2230. If the :doc:`staticfiles</ref/contrib/staticfiles>` contrib app is enabled
  2231. (as in the default project template), the :djadmin:`collectstatic` management
  2232. command will collect static files into this directory. See the how-to on
  2233. :doc:`managing static files</howto/static-files/index>` for more details about
  2234. usage.
  2235. .. warning::
  2236. This should be an initially empty destination directory for collecting
  2237. your static files from their permanent locations into one directory for
  2238. ease of deployment; it is **not** a place to store your static files
  2239. permanently. You should do that in directories that will be found by
  2240. :doc:`staticfiles</ref/contrib/staticfiles>`’s
  2241. :setting:`finders<STATICFILES_FINDERS>`, which by default, are
  2242. ``'static/'`` app sub-directories and any directories you include in
  2243. :setting:`STATICFILES_DIRS`).
  2244. .. setting:: STATIC_URL
  2245. ``STATIC_URL``
  2246. --------------
  2247. Default: ``None``
  2248. URL to use when referring to static files located in :setting:`STATIC_ROOT`.
  2249. Example: ``"/static/"`` or ``"http://static.example.com/"``
  2250. If not ``None``, this will be used as the base path for
  2251. :ref:`asset definitions<form-asset-paths>` (the ``Media`` class) and the
  2252. :doc:`staticfiles app</ref/contrib/staticfiles>`.
  2253. It must end in a slash if set to a non-empty value.
  2254. You may need to :ref:`configure these files to be served in development
  2255. <serving-static-files-in-development>` and will definitely need to do so
  2256. :doc:`in production </howto/static-files/deployment>`.
  2257. .. note::
  2258. If :setting:`STATIC_URL` is a relative path, then it will be prefixed by
  2259. the server-provided value of ``SCRIPT_NAME`` (or ``/`` if not set). This
  2260. makes it easier to serve a Django application in a subpath without adding
  2261. an extra configuration to the settings.
  2262. .. setting:: STATICFILES_DIRS
  2263. ``STATICFILES_DIRS``
  2264. --------------------
  2265. Default: ``[]`` (Empty list)
  2266. This setting defines the additional locations the staticfiles app will traverse
  2267. if the ``FileSystemFinder`` finder is enabled, e.g. if you use the
  2268. :djadmin:`collectstatic` or :djadmin:`findstatic` management command or use the
  2269. static file serving view.
  2270. This should be set to a list of strings that contain full paths to
  2271. your additional files directory(ies) e.g.::
  2272. STATICFILES_DIRS = [
  2273. "/home/special.polls.com/polls/static",
  2274. "/home/polls.com/polls/static",
  2275. "/opt/webfiles/common",
  2276. ]
  2277. Note that these paths should use Unix-style forward slashes, even on Windows
  2278. (e.g. ``"C:/Users/user/mysite/extra_static_content"``).
  2279. .. _staticfiles-dirs-prefixes:
  2280. Prefixes (optional)
  2281. ~~~~~~~~~~~~~~~~~~~
  2282. In case you want to refer to files in one of the locations with an additional
  2283. namespace, you can **optionally** provide a prefix as ``(prefix, path)``
  2284. tuples, e.g.::
  2285. STATICFILES_DIRS = [
  2286. # ...
  2287. ("downloads", "/opt/webfiles/stats"),
  2288. ]
  2289. For example, assuming you have :setting:`STATIC_URL` set to ``'/static/'``, the
  2290. :djadmin:`collectstatic` management command would collect the "stats" files
  2291. in a ``'downloads'`` subdirectory of :setting:`STATIC_ROOT`.
  2292. This would allow you to refer to the local file
  2293. ``'/opt/webfiles/stats/polls_20101022.tar.gz'`` with
  2294. ``'/static/downloads/polls_20101022.tar.gz'`` in your templates, e.g.:
  2295. .. code-block:: html+django
  2296. <a href="{% static "downloads/polls_20101022.tar.gz" %}">
  2297. .. setting:: STATICFILES_STORAGE
  2298. ``STATICFILES_STORAGE``
  2299. -----------------------
  2300. Default: ``'django.contrib.staticfiles.storage.StaticFilesStorage'``
  2301. The file storage engine to use when collecting static files with the
  2302. :djadmin:`collectstatic` management command.
  2303. A ready-to-use instance of the storage backend defined in this setting
  2304. can be found at ``django.contrib.staticfiles.storage.staticfiles_storage``.
  2305. For an example, see :ref:`staticfiles-from-cdn`.
  2306. .. setting:: STATICFILES_FINDERS
  2307. ``STATICFILES_FINDERS``
  2308. -----------------------
  2309. Default::
  2310. [
  2311. 'django.contrib.staticfiles.finders.FileSystemFinder',
  2312. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  2313. ]
  2314. The list of finder backends that know how to find static files in
  2315. various locations.
  2316. The default will find files stored in the :setting:`STATICFILES_DIRS` setting
  2317. (using ``django.contrib.staticfiles.finders.FileSystemFinder``) and in a
  2318. ``static`` subdirectory of each app (using
  2319. ``django.contrib.staticfiles.finders.AppDirectoriesFinder``). If multiple
  2320. files with the same name are present, the first file that is found will be
  2321. used.
  2322. One finder is disabled by default:
  2323. ``django.contrib.staticfiles.finders.DefaultStorageFinder``. If added to
  2324. your :setting:`STATICFILES_FINDERS` setting, it will look for static files in
  2325. the default file storage as defined by the :setting:`DEFAULT_FILE_STORAGE`
  2326. setting.
  2327. .. note::
  2328. When using the ``AppDirectoriesFinder`` finder, make sure your apps
  2329. can be found by staticfiles by adding the app to the
  2330. :setting:`INSTALLED_APPS` setting of your site.
  2331. Static file finders are currently considered a private interface, and this
  2332. interface is thus undocumented.
  2333. Core Settings Topical Index
  2334. ===========================
  2335. Cache
  2336. -----
  2337. * :setting:`CACHES`
  2338. * :setting:`CACHE_MIDDLEWARE_ALIAS`
  2339. * :setting:`CACHE_MIDDLEWARE_KEY_PREFIX`
  2340. * :setting:`CACHE_MIDDLEWARE_SECONDS`
  2341. Database
  2342. --------
  2343. * :setting:`DATABASES`
  2344. * :setting:`DATABASE_ROUTERS`
  2345. * :setting:`DEFAULT_INDEX_TABLESPACE`
  2346. * :setting:`DEFAULT_TABLESPACE`
  2347. Debugging
  2348. ---------
  2349. * :setting:`DEBUG`
  2350. * :setting:`DEBUG_PROPAGATE_EXCEPTIONS`
  2351. Email
  2352. -----
  2353. * :setting:`ADMINS`
  2354. * :setting:`DEFAULT_CHARSET`
  2355. * :setting:`DEFAULT_FROM_EMAIL`
  2356. * :setting:`EMAIL_BACKEND`
  2357. * :setting:`EMAIL_FILE_PATH`
  2358. * :setting:`EMAIL_HOST`
  2359. * :setting:`EMAIL_HOST_PASSWORD`
  2360. * :setting:`EMAIL_HOST_USER`
  2361. * :setting:`EMAIL_PORT`
  2362. * :setting:`EMAIL_SSL_CERTFILE`
  2363. * :setting:`EMAIL_SSL_KEYFILE`
  2364. * :setting:`EMAIL_SUBJECT_PREFIX`
  2365. * :setting:`EMAIL_TIMEOUT`
  2366. * :setting:`EMAIL_USE_LOCALTIME`
  2367. * :setting:`EMAIL_USE_TLS`
  2368. * :setting:`MANAGERS`
  2369. * :setting:`SERVER_EMAIL`
  2370. Error reporting
  2371. ---------------
  2372. * :setting:`DEFAULT_EXCEPTION_REPORTER`
  2373. * :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER`
  2374. * :setting:`IGNORABLE_404_URLS`
  2375. * :setting:`MANAGERS`
  2376. * :setting:`SILENCED_SYSTEM_CHECKS`
  2377. .. _file-upload-settings:
  2378. File uploads
  2379. ------------
  2380. * :setting:`DEFAULT_FILE_STORAGE`
  2381. * :setting:`FILE_UPLOAD_HANDLERS`
  2382. * :setting:`FILE_UPLOAD_MAX_MEMORY_SIZE`
  2383. * :setting:`FILE_UPLOAD_PERMISSIONS`
  2384. * :setting:`FILE_UPLOAD_TEMP_DIR`
  2385. * :setting:`MEDIA_ROOT`
  2386. * :setting:`MEDIA_URL`
  2387. Forms
  2388. -----
  2389. * :setting:`FORM_RENDERER`
  2390. Globalization (``i18n``/``l10n``)
  2391. ---------------------------------
  2392. * :setting:`DATE_FORMAT`
  2393. * :setting:`DATE_INPUT_FORMATS`
  2394. * :setting:`DATETIME_FORMAT`
  2395. * :setting:`DATETIME_INPUT_FORMATS`
  2396. * :setting:`DECIMAL_SEPARATOR`
  2397. * :setting:`FIRST_DAY_OF_WEEK`
  2398. * :setting:`FORMAT_MODULE_PATH`
  2399. * :setting:`LANGUAGE_CODE`
  2400. * :setting:`LANGUAGE_COOKIE_AGE`
  2401. * :setting:`LANGUAGE_COOKIE_DOMAIN`
  2402. * :setting:`LANGUAGE_COOKIE_HTTPONLY`
  2403. * :setting:`LANGUAGE_COOKIE_NAME`
  2404. * :setting:`LANGUAGE_COOKIE_PATH`
  2405. * :setting:`LANGUAGE_COOKIE_SAMESITE`
  2406. * :setting:`LANGUAGE_COOKIE_SECURE`
  2407. * :setting:`LANGUAGES`
  2408. * :setting:`LANGUAGES_BIDI`
  2409. * :setting:`LOCALE_PATHS`
  2410. * :setting:`MONTH_DAY_FORMAT`
  2411. * :setting:`NUMBER_GROUPING`
  2412. * :setting:`SHORT_DATE_FORMAT`
  2413. * :setting:`SHORT_DATETIME_FORMAT`
  2414. * :setting:`THOUSAND_SEPARATOR`
  2415. * :setting:`TIME_FORMAT`
  2416. * :setting:`TIME_INPUT_FORMATS`
  2417. * :setting:`TIME_ZONE`
  2418. * :setting:`USE_I18N`
  2419. * :setting:`USE_L10N`
  2420. * :setting:`USE_THOUSAND_SEPARATOR`
  2421. * :setting:`USE_TZ`
  2422. * :setting:`YEAR_MONTH_FORMAT`
  2423. HTTP
  2424. ----
  2425. * :setting:`DATA_UPLOAD_MAX_MEMORY_SIZE`
  2426. * :setting:`DATA_UPLOAD_MAX_NUMBER_FIELDS`
  2427. * :setting:`DEFAULT_CHARSET`
  2428. * :setting:`DISALLOWED_USER_AGENTS`
  2429. * :setting:`FORCE_SCRIPT_NAME`
  2430. * :setting:`INTERNAL_IPS`
  2431. * :setting:`MIDDLEWARE`
  2432. * Security
  2433. * :setting:`SECURE_BROWSER_XSS_FILTER`
  2434. * :setting:`SECURE_CONTENT_TYPE_NOSNIFF`
  2435. * :setting:`SECURE_HSTS_INCLUDE_SUBDOMAINS`
  2436. * :setting:`SECURE_HSTS_PRELOAD`
  2437. * :setting:`SECURE_HSTS_SECONDS`
  2438. * :setting:`SECURE_PROXY_SSL_HEADER`
  2439. * :setting:`SECURE_REDIRECT_EXEMPT`
  2440. * :setting:`SECURE_REFERRER_POLICY`
  2441. * :setting:`SECURE_SSL_HOST`
  2442. * :setting:`SECURE_SSL_REDIRECT`
  2443. * :setting:`SIGNING_BACKEND`
  2444. * :setting:`USE_X_FORWARDED_HOST`
  2445. * :setting:`USE_X_FORWARDED_PORT`
  2446. * :setting:`WSGI_APPLICATION`
  2447. Logging
  2448. -------
  2449. * :setting:`LOGGING`
  2450. * :setting:`LOGGING_CONFIG`
  2451. Models
  2452. ------
  2453. * :setting:`ABSOLUTE_URL_OVERRIDES`
  2454. * :setting:`FIXTURE_DIRS`
  2455. * :setting:`INSTALLED_APPS`
  2456. Security
  2457. --------
  2458. * Cross Site Request Forgery Protection
  2459. * :setting:`CSRF_COOKIE_DOMAIN`
  2460. * :setting:`CSRF_COOKIE_NAME`
  2461. * :setting:`CSRF_COOKIE_PATH`
  2462. * :setting:`CSRF_COOKIE_SAMESITE`
  2463. * :setting:`CSRF_COOKIE_SECURE`
  2464. * :setting:`CSRF_FAILURE_VIEW`
  2465. * :setting:`CSRF_HEADER_NAME`
  2466. * :setting:`CSRF_TRUSTED_ORIGINS`
  2467. * :setting:`CSRF_USE_SESSIONS`
  2468. * :setting:`SECRET_KEY`
  2469. * :setting:`X_FRAME_OPTIONS`
  2470. Serialization
  2471. -------------
  2472. * :setting:`DEFAULT_CHARSET`
  2473. * :setting:`SERIALIZATION_MODULES`
  2474. Templates
  2475. ---------
  2476. * :setting:`TEMPLATES`
  2477. Testing
  2478. -------
  2479. * Database: :setting:`TEST <DATABASE-TEST>`
  2480. * :setting:`TEST_NON_SERIALIZED_APPS`
  2481. * :setting:`TEST_RUNNER`
  2482. URLs
  2483. ----
  2484. * :setting:`APPEND_SLASH`
  2485. * :setting:`PREPEND_WWW`
  2486. * :setting:`ROOT_URLCONF`