settings.txt 112 KB

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