{"title":"配置","version":"6.1","locale":"zh-hans","docname":"ref/settings","url":"/zh-hans/6.1/ref/settings/","canonical":"https://djangodocs.dev/zh-hans/6.1/ref/settings/","summary":"核心配置 认证 消息 会话 站点 静态文件 核心配置专题索引 Warning 当你覆盖配置时要小心，特别是当默认值是一个非空的列表或字典时，如 STATICFILES_FINDERS 。确保你保留了你希望使用的 Django 功能所需要的组件。 核心配置 ¶ 下面是 Django 核心中可用的配置及其默认值的列表。下面列出了…","html":"<h1>配置<a class=\"heading-anchor\" href=\"#settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<nav class=\"contents local\" id=\"contents\">\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#core-settings\" id=\"id16\">核心配置</a></p></li>\n<li><p><a class=\"reference internal\" href=\"#auth\" id=\"id17\">认证</a></p></li>\n<li><p><a class=\"reference internal\" href=\"#messages\" id=\"id18\">消息</a></p></li>\n<li><p><a class=\"reference internal\" href=\"#sessions\" id=\"id19\">会话</a></p></li>\n<li><p><a class=\"reference internal\" href=\"#sites\" id=\"id20\">站点</a></p></li>\n<li><p><a class=\"reference internal\" href=\"#static-files\" id=\"id21\">静态文件</a></p></li>\n<li><p><a class=\"reference internal\" href=\"#core-settings-topical-index\" id=\"id22\">核心配置专题索引</a></p></li>\n</ul>\n</nav>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>当你覆盖配置时要小心，特别是当默认值是一个非空的列表或字典时，如 <a class=\"reference internal\" href=\"#std-setting-STATICFILES_FINDERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATICFILES_FINDERS</span></code></a>。确保你保留了你希望使用的 Django 功能所需要的组件。</p>\n</aside>\n<section id=\"core-settings\">\n<h2><a class=\"toc-backref\" href=\"#id16\" role=\"doc-backlink\">核心配置</a><a class=\"headerlink\" href=\"#core-settings\" title=\"Link to this heading\">¶</a></h2>\n<p>下面是 Django 核心中可用的配置及其默认值的列表。下面列出了 contrib 应用提供的设置，后面是核心配置的专题索引。关于介绍性资料，请看 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/settings/\"><span class=\"doc\">配置专题指南</span></a>。</p>\n<section id=\"absolute-url-overrides\">\n<span id=\"std-setting-ABSOLUTE_URL_OVERRIDES\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">ABSOLUTE_URL_OVERRIDES</span></code><a class=\"heading-anchor\" href=\"#absolute-url-overrides\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code> （空字典）</p>\n<p>将 <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;app_label.model_name&quot;</span></code> 字符串映射到接受模型对象并返回其 URL 的函数的字典。这是一种在每个预安装基础上插入或覆盖 <code class=\"docutils literal notranslate\"><span class=\"pre\">get_absolute_url()</span></code> 方法的方式。例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">ABSOLUTE_URL_OVERRIDES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;blogs.blog&quot;</span><span class=\"p\">:</span> <span class=\"k\">lambda</span> <span class=\"n\">o</span><span class=\"p\">:</span> <span class=\"s2\">&quot;/blogs/</span><span class=\"si\">%s</span><span class=\"s2\">/&quot;</span> <span class=\"o\">%</span> <span class=\"n\">o</span><span class=\"o\">.</span><span class=\"n\">slug</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;news.story&quot;</span><span class=\"p\">:</span> <span class=\"k\">lambda</span> <span class=\"n\">o</span><span class=\"p\">:</span> <span class=\"s2\">&quot;/stories/</span><span class=\"si\">%s</span><span class=\"s2\">/</span><span class=\"si\">%s</span><span class=\"s2\">/&quot;</span> <span class=\"o\">%</span> <span class=\"p\">(</span><span class=\"n\">o</span><span class=\"o\">.</span><span class=\"n\">pub_year</span><span class=\"p\">,</span> <span class=\"n\">o</span><span class=\"o\">.</span><span class=\"n\">slug</span><span class=\"p\">),</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>在此配置中使用的模型名称应全部为小写，与实际模型类名称的大小写无关。</p>\n</section>\n<section id=\"admins\">\n<span id=\"std-setting-ADMINS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code><a class=\"heading-anchor\" href=\"#admins\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>所有收到代码错误通知的人的列表。当 <a class=\"reference internal\" href=\"#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG=False</span></code></a> 和 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AdminEmailHandler</span></code></a> 中设置了 <a class=\"reference internal\" href=\"#std-setting-LOGGING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING</span></code></a> 时（默认情况下是这样做的），Django 会将请求／响应周期中出现的异常的详细信息通过邮件发送给这些人。</p>\n<p>Each item in the list should be an email address string. Example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">ADMINS</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s2\">&quot;john@example.com&quot;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;&quot;Ng, Mary&quot; &lt;mary@example.com&gt;&#39;</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>To safely build an address with a display name from variable content, see\n<a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#formatting-addresses\"><span class=\"std std-ref\">Formatting email addresses</span></a>, which recommends using\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/email.headerregistry.html#email.headerregistry.Address\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Address</span></code></a> over string formatting, but since this\nsetting requires a list of strings, wrap each <code class=\"docutils literal notranslate\"><span class=\"pre\">Address</span></code> in <code class=\"docutils literal notranslate\"><span class=\"pre\">str(...)</span></code>.</p>\n<aside class=\"version-note version-changed\" data-version=\"6.0\">\n<p class=\"version-note-title\">Changed in Django 6.0</p><p>In older versions, required a list of (name, address) tuples.</p>\n</aside>\n</section>\n<section id=\"allowed-hosts\">\n<span id=\"std-setting-ALLOWED_HOSTS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">ALLOWED_HOSTS</span></code><a class=\"heading-anchor\" href=\"#allowed-hosts\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>一个代表这个 Django 网站可以服务的主机／域名的字符串列表。这是一个安全措施，以防止 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/security/#host-headers-virtual-hosting\"><span class=\"std std-ref\">HTTP 主机头攻击</span></a> ，即使在许多看似安全的 Web 服务器配置下也有可能发生。</p>\n<p>这个列表中的值可以是完全限定的名称（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">'www.example.com</span></code>），在这种情况下，它们将与请求的 <code class=\"docutils literal notranslate\"><span class=\"pre\">Host</span></code> 头完全匹配（不区分大小写，不包括端口）。以英文句号开头的值可以用作子域通配符。<code class=\"docutils literal notranslate\"><span class=\"pre\">'.example.com'</span></code> 将匹配 <code class=\"docutils literal notranslate\"><span class=\"pre\">example.com</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">www.example.com</span></code> 和 <code class=\"docutils literal notranslate\"><span class=\"pre\">example.com</span></code> 的任何其他子域。<code class=\"docutils literal notranslate\"><span class=\"pre\">'*'</span></code> 的值将匹配任何东西；在这种情况下，你要负责提供你自己的 <code class=\"docutils literal notranslate\"><span class=\"pre\">Host</span></code> 头的验证（也许是在一个中间件中；如果是这样，这个中间件必须首先在 <a class=\"reference internal\" href=\"#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a> 中列出）。</p>\n<p>Django 也允许在任何条目中使用 <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Fully_qualified_domain_name\">完全合格的域名（FQDN）</a> 。有些浏览器在 <code class=\"docutils literal notranslate\"><span class=\"pre\">Host</span></code> 头中包含了一个尾部的点，Django 在执行主机验证时将其去掉。</p>\n<p>If the <code class=\"docutils literal notranslate\"><span class=\"pre\">Host</span></code> header (or <code class=\"docutils literal notranslate\"><span class=\"pre\">X-Forwarded-Host</span></code> if\n<a class=\"reference internal\" href=\"#std-setting-USE_X_FORWARDED_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_X_FORWARDED_HOST</span></code></a> is enabled) does not match any value in this\nlist, the <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/request-response/#django.http.HttpRequest.get_host\" title=\"django.http.HttpRequest.get_host\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">django.http.HttpRequest.get_host()</span></code></a> method will raise\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/exceptions/#django.core.exceptions.SuspiciousOperation\" title=\"django.core.exceptions.SuspiciousOperation\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">SuspiciousOperation</span></code></a>.</p>\n<p>当 <code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG`为``True`</span></code> 和 <code class=\"docutils literal notranslate\"><span class=\"pre\">ALLOWED_HOSTS</span></code> 为空时，主机将根据 <code class=\"docutils literal notranslate\"><span class=\"pre\">['.localhost',</span> <span class=\"pre\">'127.0.0.1',</span> <span class=\"pre\">'[::1]']</span></code> 进行验证。</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">ALLOWED_HOSTS</span></code> 也是 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/advanced/#topics-testing-advanced-multiple-hosts\"><span class=\"std std-ref\">在运行测试时进行检查的</span></a>。</p>\n<p>This validation only applies via <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/request-response/#django.http.HttpRequest.get_host\" title=\"django.http.HttpRequest.get_host\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_host()</span></code></a>;\nif your code accesses the <code class=\"docutils literal notranslate\"><span class=\"pre\">Host</span></code> header directly from <code class=\"docutils literal notranslate\"><span class=\"pre\">request.META</span></code> you\nare bypassing this security protection.</p>\n</section>\n<section id=\"append-slash\">\n<span id=\"std-setting-APPEND_SLASH\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code><a class=\"heading-anchor\" href=\"#append-slash\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code></p>\n<p>当设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> 时，如果请求的 URL 不符合 URLconf 中的任何模式，并且不以斜线结尾，则会发出一个 HTTP 重定向到相同的URL，并附加一个斜线。注意，重定向可能会导致 POST 请求中提交的任何数据丢失。</p>\n<p><a class=\"reference internal\" href=\"#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a> 的配置只有在安装了 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.common.CommonMiddleware\" title=\"django.middleware.common.CommonMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CommonMiddleware</span></code></a> 的情况下才会使用（参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/middleware/\"><span class=\"doc\">中间件</span></a>）。也请参见 <a class=\"reference internal\" href=\"#std-setting-PREPEND_WWW\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PREPEND_WWW</span></code></a>。</p>\n</section>\n<section id=\"caches\">\n<span id=\"std-setting-CACHES\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CACHES</span></code><a class=\"heading-anchor\" href=\"#caches\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.cache.backends.locmem.LocMemCache&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>一个包含所有 Django 缓存配置的字典。它是一个嵌套的字典，其内容将缓存别名映射到一个包含单个缓存选项的字典中。</p>\n<p><a class=\"reference internal\" href=\"#std-setting-CACHES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CACHES</span></code></a> 配置必须设置一个 <code class=\"docutils literal notranslate\"><span class=\"pre\">default</span></code> 缓存；也可以指定任何数量的附加缓存。如果你使用的是本地内存缓存以外的缓存后端，或者你需要定义多个缓存，则需要其他选项。以下是可用的缓存选项。</p>\n<section id=\"backend\">\n<span id=\"std-setting-CACHES-BACKEND\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code><a class=\"heading-anchor\" href=\"#backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>要使用的缓存后端。内置的缓存后端有：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.core.cache.backends.db.DatabaseCache'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.core.cache.backends.dummy.DummyCache'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.core.cache.backends.filebased.FileBasedCache'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.core.cache.backends.locmem.LocMemCache'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.core.cache.backends.memcached.PyMemcacheCache'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.core.cache.backends.memcached.PyLibMCCache'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.core.cache.backends.redis.RedisCache'</span></code></p></li>\n</ul>\n<p>你可以通过将 <a class=\"reference internal\" href=\"#std-setting-CACHES-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code></a> 设置为一个完全限定的缓存后端类的路径（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">mypackage.backends.whatever.WhateverCache</span></code>），来使用一个不在 Django 中的缓存后端。</p>\n</section>\n<section id=\"key-function\">\n<span id=\"std-setting-CACHES-KEY_FUNCTION\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">KEY_FUNCTION</span></code><a class=\"heading-anchor\" href=\"#key-function\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>A string containing a dotted path to a function (or any callable) that defines\nhow to compose a key, prefix, and version into a final cache key. The default\nfunction converts the components to strings and joins them with colons, as\nshown in the <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/cache/#cache-key-transformation\"><span class=\"std std-ref\">cache documentation</span></a>.</p>\n<p>你可以使用任何你想要的密钥函数，只要它有相同的参数签名。</p>\n</section>\n<section id=\"key-prefix\">\n<span id=\"std-setting-CACHES-KEY_PREFIX\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">KEY_PREFIX</span></code><a class=\"heading-anchor\" href=\"#key-prefix\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>一个自动包含在 Django 服务器使用的所有缓存键中的字符串（默认情况下是前缀）。</p>\n<p>查看 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/cache/#cache-key-prefixing\"><span class=\"std std-ref\">缓存文档</span></a> 获取更多信息。</p>\n</section>\n<section id=\"location\">\n<span id=\"std-setting-CACHES-LOCATION\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">LOCATION</span></code><a class=\"heading-anchor\" href=\"#location\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>要使用的高速缓存的位置。可能是文件系统缓存的目录，memcache 服务器的主机和端口，或者是本地内存缓存的识别名称，例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">CACHES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.cache.backends.filebased.FileBasedCache&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;LOCATION&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;/var/tmp/django_cache&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n</section>\n<section id=\"options\">\n<span id=\"std-setting-CACHES-OPTIONS\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code><a class=\"heading-anchor\" href=\"#options\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>传递给缓存后端的额外参数。可用的参数根据你的缓存后端不同而不同。</p>\n<p>关于可用参数的一些信息可以在 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/cache/#cache-arguments\"><span class=\"std std-ref\">缓存参数</span></a> 文档中找到。更多信息，请查阅你的后端模块自己的文档。</p>\n</section>\n<section id=\"timeout\">\n<span id=\"std-setting-CACHES-TIMEOUT\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">TIMEOUT</span></code><a class=\"heading-anchor\" href=\"#timeout\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">300</span></code></p>\n<p>缓存条目被视为过期之前的秒数。如果此设置的值为 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，则缓存条目不会过期。值为 <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code> 会导致键立即过期（实际上是&quot;不缓存&quot;）。</p>\n</section>\n<section id=\"version\">\n<span id=\"std-setting-CACHES-VERSION\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">VERSION</span></code><a class=\"heading-anchor\" href=\"#version\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">1</span></code></p>\n<p>Django 服务器生成的缓存密钥的默认版本号。</p>\n<p>查看 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/cache/#cache-versioning\"><span class=\"std std-ref\">缓存文档</span></a> 获取更多信息。</p>\n</section>\n</section>\n<section id=\"cache-middleware-alias\">\n<span id=\"std-setting-CACHE_MIDDLEWARE_ALIAS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CACHE_MIDDLEWARE_ALIAS</span></code><a class=\"heading-anchor\" href=\"#cache-middleware-alias\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'default'</span></code></p>\n<p>用于 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/cache/#the-per-site-cache\"><span class=\"std std-ref\">缓存中间件</span></a> 的缓存连接。</p>\n</section>\n<section id=\"cache-middleware-key-prefix\">\n<span id=\"std-setting-CACHE_MIDDLEWARE_KEY_PREFIX\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CACHE_MIDDLEWARE_KEY_PREFIX</span></code><a class=\"heading-anchor\" href=\"#cache-middleware-key-prefix\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>由 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/cache/#the-per-site-cache\"><span class=\"std std-ref\">缓存中间件</span></a> 生成的缓存密钥前缀的字符串。这个前缀与 <a class=\"reference internal\" href=\"#std-setting-CACHES-KEY_PREFIX\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">KEY_PREFIX</span></code></a> 的配置结合在一起，而不是取代它。</p>\n<p>参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/cache/\"><span class=\"doc\">Django 缓存框架</span></a>。</p>\n</section>\n<section id=\"cache-middleware-seconds\">\n<span id=\"std-setting-CACHE_MIDDLEWARE_SECONDS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CACHE_MIDDLEWARE_SECONDS</span></code><a class=\"heading-anchor\" href=\"#cache-middleware-seconds\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">600</span></code></p>\n<p>默认的 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/cache/#the-per-site-cache\"><span class=\"std std-ref\">缓存中间件</span></a> 缓存页面的整数秒数。</p>\n<p>参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/cache/\"><span class=\"doc\">Django 缓存框架</span></a>。</p>\n</section>\n<section id=\"csrf-cookie-age\">\n<span id=\"std-setting-CSRF_COOKIE_AGE\"></span><span id=\"settings-csrf\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_AGE</span></code><a class=\"heading-anchor\" href=\"#csrf-cookie-age\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">31449600</span></code> （约 1 年，以秒为单位）</p>\n<p>CSRF cookie 的寿命，以秒为单位。</p>\n<p>设置长效过期时间的原因是为了避免在用户关闭浏览器或将某一页面作为书签，然后从浏览器缓存中加载该页面时出现问题。如果没有持久性 Cookie，这种情况下表单提交会失败。</p>\n<p>一些浏览器（特别是 Internet Explorer）可能不允许使用持久性 cookie，或可能使 cookie jar 的索引在磁盘上损坏，从而导致 CSRF 保护检查（有时是间歇性的）失败。将此设置改为 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，以使用基于会话的 CSRF cookie，它将 cookie 保存在内存中，而不是持久性存储中。</p>\n</section>\n<section id=\"csrf-cookie-domain\">\n<span id=\"std-setting-CSRF_COOKIE_DOMAIN\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_DOMAIN</span></code><a class=\"heading-anchor\" href=\"#csrf-cookie-domain\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>The domain to be used when setting the CSRF cookie. This can be useful for\neasily allowing cross-subdomain requests to be excluded from the normal cross\nsite request forgery protection. It should be set to a string such as\n<code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;.example.com&quot;</span></code> to allow a POST request from a form on one subdomain to be\naccepted by a view served from another subdomain.</p>\n<p>请注意，这个配置的存在并不意味着 Django 的 CSRF 保护在默认情况下是安全的，不会受到跨子域的攻击——请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/csrf/#csrf-limitations\"><span class=\"std std-ref\">CSRF 限制</span></a> 部分。</p>\n</section>\n<section id=\"csrf-cookie-httponly\">\n<span id=\"std-setting-CSRF_COOKIE_HTTPONLY\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_HTTPONLY</span></code><a class=\"heading-anchor\" href=\"#csrf-cookie-httponly\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否对 CSRF cookie 使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpOnly</span></code> 标志。如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，客户端的 JavaScript 将无法访问 CSRF cookie。</p>\n<p>将 CSRF cookie 指定为 <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpOnly</span></code> 并不能提供任何实际的保护，因为 CSRF 只是为了防止跨域攻击。如果攻击者可以通过 JavaScript 读取 cookie，就浏览器所知，他们已经在同一个域上了，所以他们可以做任何他们喜欢的事情。（XSS 是一个比 CSRF 更大的漏洞）。</p>\n<p>虽然这种配置没有提供什么实际的好处，但有时也会被安全审计人员要求。</p>\n<p>如果你启用了这个功能，并且需要通过 AJAX 请求发送 CSRF 标记的值，你的 JavaScript 必须 <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/csrf/#acquiring-csrf-token-from-html\"><span class=\"std std-ref\">从隐藏的 CSRF 标记表单输入</span></a> 中提取值而不是 <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/csrf/#acquiring-csrf-token-from-cookie\"><span class=\"std std-ref\">从 cookie</span></a>。</p>\n<p>关于 <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpOnly</span></code> 的详细信息，请参见 <a class=\"reference internal\" href=\"#std-setting-SESSION_COOKIE_HTTPONLY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_HTTPONLY</span></code></a>。</p>\n</section>\n<section id=\"csrf-cookie-name\">\n<span id=\"std-setting-CSRF_COOKIE_NAME\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_NAME</span></code><a class=\"heading-anchor\" href=\"#csrf-cookie-name\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'csrftoken'</span></code></p>\n<p>用于 CSRF 认证令牌的 cookie 的名称。这可以是任何你想要的名字（只要它与你的应用程序中的其他 cookie 名字不同）。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/csrf/\"><span class=\"doc\">跨站请求伪造保护</span></a>。</p>\n</section>\n<section id=\"csrf-cookie-path\">\n<span id=\"std-setting-CSRF_COOKIE_PATH\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_PATH</span></code><a class=\"heading-anchor\" href=\"#csrf-cookie-path\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'/'</span></code></p>\n<p>在 CSRF cookie 上设置的路径。这个路径应该与你的 Django 安装的 URL 路径相匹配，或者是该路径的父路径。</p>\n<p>如果你有多个 Django 实例在同一个主机名下运行，这个功能很有用。他们可以使用不同的 cookie 路径，而且每个实例只能看到自己的 CSRF cookie。</p>\n</section>\n<section id=\"csrf-cookie-samesite\">\n<span id=\"std-setting-CSRF_COOKIE_SAMESITE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_SAMESITE</span></code><a class=\"heading-anchor\" href=\"#csrf-cookie-samesite\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'Lax'</span></code></p>\n<p>CSRF cookie 上 <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value\">SameSite</a> 标志的值。该标志可防止在跨站点请求中发送 cookie。</p>\n<p>关于 <code class=\"docutils literal notranslate\"><span class=\"pre\">SameSite</span></code> 的详细信息，请参见 <a class=\"reference internal\" href=\"#std-setting-SESSION_COOKIE_SAMESITE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_SAMESITE</span></code></a>。</p>\n</section>\n<section id=\"csrf-cookie-secure\">\n<span id=\"std-setting-CSRF_COOKIE_SECURE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_SECURE</span></code><a class=\"heading-anchor\" href=\"#csrf-cookie-secure\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否为 CSRF cookie 使用安全 cookie。如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，cookie 将被标记为 <code class=\"docutils literal notranslate\"><span class=\"pre\">安全</span></code>，这意味着浏览器可以确保 cookie 只在 HTTPS 连接下发送。</p>\n</section>\n<section id=\"csrf-use-sessions\">\n<span id=\"std-setting-CSRF_USE_SESSIONS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_USE_SESSIONS</span></code><a class=\"heading-anchor\" href=\"#csrf-use-sessions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否将 CSRF 标记存储在用户的会话中，而不是 cookie 中。这需要使用 <code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.session</span></code>。</p>\n<p>将 CSRF 令牌存储在 cookie 中（Django 的默认值）是安全的，但将其存储在 session 中是其他 Web 框架的常见做法，因此有时会被安全审计人员要求。</p>\n<p>由于 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/views/#error-views\"><span class=\"std std-ref\">默认错误视图</span></a> 需要CSRF令牌，所以 <code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code> 必须出现在 <a class=\"reference internal\" href=\"#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a> 中，在任何可能引发异常以触发错误视图的中间件（如 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/exceptions/#django.core.exceptions.PermissionDenied\" title=\"django.core.exceptions.PermissionDenied\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">PermissionDenied</span></code></a>）之前，如果你正在使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_USE_SESSIONS</span></code>。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#middleware-ordering\"><span class=\"std std-ref\">中间件顺序</span></a>。</p>\n</section>\n<section id=\"csrf-failure-view\">\n<span id=\"std-setting-CSRF_FAILURE_VIEW\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_FAILURE_VIEW</span></code><a class=\"heading-anchor\" href=\"#csrf-failure-view\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.views.csrf.csrf_failure'</span></code></p>\n<p>当传入的请求被 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/csrf/\"><span class=\"doc\">CSRF 保护</span></a> 拒绝时，要使用的视图函数的点分隔路径。该函数应具有以下签名：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">csrf_failure</span><span class=\"p\">(</span><span class=\"n\">request</span><span class=\"p\">,</span> <span class=\"n\">reason</span><span class=\"o\">=</span><span class=\"s2\">&quot;&quot;</span><span class=\"p\">):</span> <span class=\"o\">...</span>\n</code></pre></div>\n<p>其中 <code class=\"docutils literal notranslate\"><span class=\"pre\">reason</span></code> 是一个简短的消息（针对开发者或日志记录，而不是针对终端用户），表示请求被拒绝的原因，它应该返回一个 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/request-response/#django.http.HttpResponseForbidden\" title=\"django.http.HttpResponseForbidden\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponseForbidden</span></code></a>。</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.views.csrf.csrf_failure()</span></code> 接受一个额外的 <code class=\"docutils literal notranslate\"><span class=\"pre\">template_name</span></code> 参数，默认为 <code class=\"docutils literal notranslate\"><span class=\"pre\">'403_csrf.html'</span></code>。如果存在该名称的模板，它将被用来渲染页面。</p>\n</section>\n<section id=\"csrf-header-name\">\n<span id=\"std-setting-CSRF_HEADER_NAME\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_HEADER_NAME</span></code><a class=\"heading-anchor\" href=\"#csrf-header-name\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'HTTP_X_CSRFTOKEN'</span></code></p>\n<p>用于 CSRF 认证的请求头的名称。</p>\n<p>与 <code class=\"docutils literal notranslate\"><span class=\"pre\">request.META</span></code> 中的其他 HTTP 头文件一样，从服务器接收到的头文件名通过将所有字符转换为大写字母，用下划线代替任何连字符，并在名称中添加 <code class=\"docutils literal notranslate\"><span class=\"pre\">'HTTP_'</span></code> 前缀进行规范化。例如，如果你的客户端发送了一个 <code class=\"docutils literal notranslate\"><span class=\"pre\">'X-XSRF-TOKEN'</span></code> 头，配置应该是 <code class=\"docutils literal notranslate\"><span class=\"pre\">'HTTP_X_XSRF_TOKEN'</span></code>。</p>\n</section>\n<section id=\"csrf-trusted-origins\">\n<span id=\"std-setting-CSRF_TRUSTED_ORIGINS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">CSRF_TRUSTED_ORIGINS</span></code><a class=\"heading-anchor\" href=\"#csrf-trusted-origins\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>一组信任的来源，用于不安全的请求（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">POST</span></code>）。</p>\n<p>对于包含 <code class=\"docutils literal notranslate\"><span class=\"pre\">Origin</span></code> 头的请求，Django 的 CSRF 保护要求该头部与 <code class=\"docutils literal notranslate\"><span class=\"pre\">Host</span></code> 头中的来源匹配。</p>\n<p>For a secure (determined by <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/request-response/#django.http.HttpRequest.is_secure\" title=\"django.http.HttpRequest.is_secure\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">is_secure()</span></code></a>) unsafe\nrequest that doesn't include the <code class=\"docutils literal notranslate\"><span class=\"pre\">Origin</span></code> header, the request must include a\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Referer</span></code> header that matches the origin in the <code class=\"docutils literal notranslate\"><span class=\"pre\">Host</span></code> header.</p>\n<p>这些检查可以防止，例如，来自 <code class=\"docutils literal notranslate\"><span class=\"pre\">subdomain.example.com</span></code> 的 <code class=\"docutils literal notranslate\"><span class=\"pre\">POST</span></code> 请求成功访问 <code class=\"docutils literal notranslate\"><span class=\"pre\">api.example.com</span></code>。如果你需要跨域不安全请求，继续上面的示例，在此列表中添加 <code class=\"docutils literal notranslate\"><span class=\"pre\">'https://subdomain.example.com'</span></code> （如果请求来自不安全页面，也可以添加 <code class=\"docutils literal notranslate\"><span class=\"pre\">http://...</span></code>）。</p>\n<p>这个设置也支持子域名，因此你可以添加 <code class=\"docutils literal notranslate\"><span class=\"pre\">'https://*.example.com'</span></code>，例如，以允许来自 <code class=\"docutils literal notranslate\"><span class=\"pre\">example.com</span></code> 的所有子域名的访问。</p>\n</section>\n<section id=\"databases\">\n<span id=\"std-setting-DATABASES\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code><a class=\"heading-anchor\" href=\"#databases\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code> （空字典）</p>\n<p>一个包含所有数据库配置的字典，用于 Django。它是一个嵌套的字典，其内容是将一个数据库别名映射到一个包含单个数据库选项的字典中。</p>\n<p><a class=\"reference internal\" href=\"#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a> 配置必须设置一个 <code class=\"docutils literal notranslate\"><span class=\"pre\">default</span></code> 数据库；也可以指定任何数量的其他数据库。</p>\n<p>最简单的配置文件是使用 SQLite 的单数据库配置。可以通过以下方式进行配置：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.sqlite3&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;mydatabase&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>当连接到其他数据库后端时，如 MariaDB、MySQL、Oracle 或 PostgreSQL，将需要额外的连接参数。请参阅下面的 <a class=\"reference internal\" href=\"#std-setting-DATABASE-ENGINE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ENGINE</span></code></a> 配置，了解如何指定其他数据库类型。这个例子是针对 PostgreSQL：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.postgresql&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;mydatabase&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;USER&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;mydatabaseuser&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;PASSWORD&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;mypassword&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;HOST&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;127.0.0.1&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;PORT&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;5432&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>以下是更复杂配置可能需要的内部选项：</p>\n<section id=\"atomic-requests\">\n<span id=\"std-setting-DATABASE-ATOMIC_REQUESTS\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">ATOMIC_REQUESTS</span></code><a class=\"heading-anchor\" href=\"#atomic-requests\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>将此设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，以将每个视图包裹在这个数据库的事务中。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/db/transactions/#tying-transactions-to-http-requests\"><span class=\"std std-ref\">连结事务与 HTTP 请求</span></a>。</p>\n</section>\n<section id=\"autocommit\">\n<span id=\"std-setting-DATABASE-AUTOCOMMIT\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">AUTOCOMMIT</span></code><a class=\"heading-anchor\" href=\"#autocommit\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code></p>\n<p>如果你想 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/db/transactions/#deactivate-transaction-management\"><span class=\"std std-ref\">禁用 Django 的事务管理</span></a> 并实现你自己的事务管理，请将此设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>。</p>\n</section>\n<section id=\"engine\">\n<span id=\"std-setting-DATABASE-ENGINE\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">ENGINE</span></code><a class=\"heading-anchor\" href=\"#engine\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>要使用的数据库后端。内置的数据库后端有：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.db.backends.postgresql'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.db.backends.mysql'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.db.backends.sqlite3'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.db.backends.oracle'</span></code></p></li>\n</ul>\n<p>你可以通过将 <code class=\"docutils literal notranslate\"><span class=\"pre\">ENGINE</span></code> 设置为一个完全限定的路径（例如： <code class=\"docutils literal notranslate\"><span class=\"pre\">mypackage.backends.whatever</span></code>），来使用一个不在 Django 中的数据库后端。</p>\n</section>\n<section id=\"host\">\n<span id=\"std-setting-HOST\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">HOST</span></code><a class=\"heading-anchor\" href=\"#host\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>连接到数据库时使用的主机。空字符串表示本地主机。不用于 SQLite。</p>\n<p>如果这个值以斜线（<code class=\"docutils literal notranslate\"><span class=\"pre\">'/'</span></code>）开头，并且你正在使用 MySQL，MySQL 将通过 Unix 套接字连接到指定的套接字。例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"s2\">&quot;HOST&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;/var/run/mysql&quot;</span>\n</code></pre></div>\n<p>如果你使用的是 MySQL，并且这个值 <em>没有</em> 以斜线开头，那么这个值被认为是主机。</p>\n<p>如果你使用的是 PostgreSQL，默认情况下（空 <a class=\"reference internal\" href=\"#std-setting-HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">HOST</span></code></a>），与数据库的连接是通过 UNIX 域套接字（<code class=\"docutils literal notranslate\"><span class=\"pre\">pg_hba.conf</span></code> 中的 'local' ）完成的。如果你的 UNIX 域套接字不在标准位置，请使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">postgresql.conf</span></code> 中的 <code class=\"docutils literal notranslate\"><span class=\"pre\">unix_socket_directory</span></code> 的相同值。如果你想通过 TCP 套接字连接，将 <a class=\"reference internal\" href=\"#std-setting-HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">HOST</span></code></a> 设置为 'localhost' 或 '127.0.0.1'（<code class=\"docutils literal notranslate\"><span class=\"pre\">pg_hba.conf</span></code> 中的 'host' 行）。在 Windows 上，你应该总是定义 <a class=\"reference internal\" href=\"#std-setting-HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">HOST</span></code></a>，因为 UNIX 域套接字是不可用的。</p>\n</section>\n<section id=\"name\">\n<span id=\"std-setting-NAME\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">NAME</span></code><a class=\"heading-anchor\" href=\"#name\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>要使用的数据库的名称。对于 SQLite，它是数据库文件的完整路径。当指定路径时，总是使用斜线，即使在 Windows 上也是如此（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">C:/homes/user/mysite/sqlite3.db</span></code>）。</p>\n</section>\n<section id=\"conn-max-age\">\n<span id=\"std-setting-CONN_MAX_AGE\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">CONN_MAX_AGE</span></code><a class=\"heading-anchor\" href=\"#conn-max-age\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code></p>\n<p>数据库连接的生命周期，以秒为单位的整数。使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code> 来在每个请求结束时关闭数据库连接（Django 的历史行为），使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> 来表示无限的 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/databases/#persistent-database-connections\"><span class=\"std std-ref\">持久数据库连接</span></a>。</p>\n</section>\n<section id=\"conn-health-checks\">\n<span id=\"std-setting-CONN_HEALTH_CHECKS\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">CONN_HEALTH_CHECKS</span></code><a class=\"heading-anchor\" href=\"#conn-health-checks\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，在每个执行数据库访问的请求中重用现有的 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/databases/#persistent-database-connections\"><span class=\"std std-ref\">持久数据库连接</span></a> 之前，将对它们进行健康检查。如果健康检查失败，当连接不再可用但数据库服务器已准备好接受和提供新连接时（例如，在数据库服务器重新启动并关闭现有连接后），将重新建立连接，而不会导致请求失败。</p>\n</section>\n<section id=\"std-setting-OPTIONS\">\n<span id=\"id1\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code><a class=\"heading-anchor\" href=\"#std-setting-OPTIONS\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code> （空字典）</p>\n<p>连接到数据库时要使用的额外参数。可用的参数根据你的数据库后端不同而不同。</p>\n<p>关于可用参数的一些信息可以在 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/databases/\"><span class=\"doc\">数据库后端</span></a> 文档中找到。更多信息，请查阅你的后端模块自己的文档。</p>\n</section>\n<section id=\"password\">\n<span id=\"std-setting-PASSWORD\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">PASSWORD</span></code><a class=\"heading-anchor\" href=\"#password\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>连接到数据库时使用的密码。不用于 SQLite。</p>\n</section>\n<section id=\"port\">\n<span id=\"std-setting-PORT\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">PORT</span></code><a class=\"heading-anchor\" href=\"#port\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>连接到数据库时要使用的端口。空字符串表示默认端口。不用于 SQLite。</p>\n</section>\n<section id=\"time-zone\">\n<span id=\"std-setting-DATABASE-TIME_ZONE\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code><a class=\"heading-anchor\" href=\"#time-zone\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>代表该数据库连接时区的字符串或 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>。<a class=\"reference internal\" href=\"#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a> 配置的这个内部选项与一般的 <a class=\"reference internal\" href=\"#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a> 配置接受相同的值。</p>\n<p>当 <a class=\"reference internal\" href=\"#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code></a> 为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> 时，从数据库读取的日期时间会返回带有时区设置为此选项值的感知日期时间，如果为 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，则设置为 UTC。</p>\n<p>当 <a class=\"reference internal\" href=\"#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code></a> 是 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> 时，设置此选项是错误的。</p>\n<ul>\n<li><p>如果数据库后端不支持时区（如 SQLite、MySQL、Oracle），如果设置了这个选项，Django 会根据这个选项以当地时间读写日期，如果没有设置，则以 UTC 时间读写。</p>\n<p>改变连接时区会改变从数据库中读取和写入日期的方式。</p>\n<ul class=\"simple\">\n<li><p>如果 Django 管理数据库，并且没有强烈的理由进行更改，最好将此选项保持未设置。最好将日期时间存储为 UTC，因为这可以避免在夏令时变化期间出现模糊或不存在的日期时间。另外，接收 UTC 日期时间可以保持日期时间算术的简单性 — 不需要考虑夏令时转换期间潜在的偏移更改。</p></li>\n<li><p>如果你连接的第三方数据库以当地时间而不是 UTC 存储日期，那么你必须将这个选项设置为合适的时区。同样，如果 Django 管理数据库，但第三方系统连接到同一个数据库，并希望找到当地时间的日期，那么你必须设置这个选项。</p></li>\n</ul>\n</li>\n<li><p>如果数据库后端支持时区（例如，PostgreSQL），那么数据库连接的时区将设置为此值。</p>\n<p>尽管很少需要设置 <code class=\"docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code> 选项，但在某些情况下，这是必要的。特别是在处理涉及日期/时间函数的原始查询时，建议与一般的 <a class=\"reference internal\" href=\"#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a> 设置相匹配，例如 PostgreSQL 的 <code class=\"docutils literal notranslate\"><span class=\"pre\">date_trunc()</span></code> 或 <code class=\"docutils literal notranslate\"><span class=\"pre\">generate_series()</span></code>，尤其是在生成基于时间的系列时，会发生夏令时转换。</p>\n<p>这个值可以随时更改，数据库将处理日期时间到配置的时区的转换。</p>\n<p>然而，这也有一个缺点：接收所有日期时间都以本地时间表示会使日期时间运算变得更加复杂 — 你必须考虑夏令时转换期间可能发生的偏移变化。</p>\n<p>考虑在原始 SQL 查询中使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">AT</span> <span class=\"pre\">TIME</span> <span class=\"pre\">ZONE</span></code> 明确转换为当地时间，而不是设置 <code class=\"docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code> 选项。</p>\n</li>\n</ul>\n</section>\n<section id=\"disable-server-side-cursors\">\n<span id=\"std-setting-DATABASE-DISABLE_SERVER_SIDE_CURSORS\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">DISABLE_SERVER_SIDE_CURSORS</span></code><a class=\"heading-anchor\" href=\"#disable-server-side-cursors\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>如果你想通过 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/models/querysets/#django.db.models.query.QuerySet.iterator\" title=\"django.db.models.query.QuerySet.iterator\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">QuerySet.iterator()</span></code></a> 禁用服务器端游标的使用，请将其设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>。 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/databases/#transaction-pooling-server-side-cursors\"><span class=\"std std-ref\">事务池和服务器端游标</span></a> 描述了使用情况。</p>\n<p>这是 PostgreSQL 特有的配置。</p>\n</section>\n<section id=\"user\">\n<span id=\"std-setting-USER\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">USER</span></code><a class=\"heading-anchor\" href=\"#user\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>连接数据库时要使用的用户名。不用于 SQLite。</p>\n</section>\n<section id=\"test\">\n<span id=\"std-setting-DATABASE-TEST\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">TEST</span></code><a class=\"heading-anchor\" href=\"#test\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code> （空字典）</p>\n<p>测试数据库的设置字典；关于测试数据库的创建和使用的更多细节，见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/overview/#the-test-database\"><span class=\"std std-ref\">测试数据库</span></a>。</p>\n<p>下面是一个测试数据库配置的例子：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">DATABASES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.postgresql&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;USER&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;mydatabaseuser&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;mydatabase&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;TEST&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;mytestdatabase&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">TEST</span></code> 字典中的下列键可供使用：</p>\n<section id=\"charset\">\n<span id=\"std-setting-TEST_CHARSET\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">CHARSET</span></code><a class=\"heading-anchor\" href=\"#charset\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>用于创建测试数据库的字符集编码。这个字符串的值是直接传递给数据库的，所以它的格式是特定于后端的。</p>\n<p>由 <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/multibyte.html\">PostgreSQL</a> （<code class=\"docutils literal notranslate\"><span class=\"pre\">postgresql</span></code>）和 <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/charset-charsets.html\">MySQL</a> （<code class=\"docutils literal notranslate\"><span class=\"pre\">mysql</span></code>）后端支持。</p>\n</section>\n<section id=\"collation\">\n<span id=\"std-setting-TEST_COLLATION\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">COLLATION</span></code><a class=\"heading-anchor\" href=\"#collation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>创建测试数据库时要使用的字符序。这个值是直接传递给后端的，所以它的格式是后端特定的。</p>\n<p>仅支持 <code class=\"docutils literal notranslate\"><span class=\"pre\">mysql</span></code> 后端（详见 <a class=\"reference external\" href=\"https://dev.mysql.com/doc/refman/en/charset-charsets.html\">MySQL 手册</a> ）。</p>\n</section>\n<section id=\"dependencies\">\n<span id=\"std-setting-TEST_DEPENDENCIES\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">DEPENDENCIES</span></code><a class=\"heading-anchor\" href=\"#dependencies\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">['default']</span></code>，适用于除 <code class=\"docutils literal notranslate\"><span class=\"pre\">default</span></code> 以外的所有数据库，后者没有依赖性。</p>\n<p>数据库的创建顺序依赖性。详见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/advanced/#topics-testing-creation-dependencies\"><span class=\"std std-ref\">控制测试数据库的创建顺序</span></a> 的文档。</p>\n</section>\n<section id=\"migrate\">\n<span id=\"std-setting-TEST_MIGRATE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">MIGRATE</span></code><a class=\"heading-anchor\" href=\"#migrate\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code></p>\n<p>当设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> 时，在创建测试数据库时不会运行迁移。这类似于在 <a class=\"reference internal\" href=\"#std-setting-MIGRATION_MODULES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIGRATION_MODULES</span></code></a> 中设置 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> 作为一个值，但适用于所有应用程序。</p>\n</section>\n<section id=\"mirror\">\n<span id=\"std-setting-TEST_MIRROR\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">MIRROR</span></code><a class=\"heading-anchor\" href=\"#mirror\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>这个数据库应该在测试期间进行镜像的数据库的别名。它依赖于事务，因此必须在 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/tools/#django.test.TransactionTestCase\" title=\"django.test.TransactionTestCase\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">TransactionTestCase</span></code></a> 而不是 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/tools/#django.test.TestCase\" title=\"django.test.TestCase\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">TestCase</span></code></a> 中使用。</p>\n<p>该配置允许测试多个数据库的主／副本（某些数据库称为主／从）配置。详情请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/advanced/#topics-testing-primaryreplica\"><span class=\"std std-ref\">测试主／副本配置</span></a> 的文档。</p>\n</section>\n<section id=\"std-setting-TEST_NAME\">\n<span id=\"id2\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">NAME</span></code><a class=\"heading-anchor\" href=\"#std-setting-TEST_NAME\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>运行测试套件时要使用的数据库名称。</p>\n<p>如果 SQLite 数据库引擎使用默认值（<code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>），则测试将使用内存常驻数据库。对于所有其他数据库引擎，测试数据库将使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">'test_'</span> <span class=\"pre\">+</span> <span class=\"pre\">DATABASE_NAME</span></code> 的名称。</p>\n<p>查看 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/overview/#the-test-database\"><span class=\"std std-ref\">测试数据库</span></a>。</p>\n</section>\n<section id=\"template\">\n<span id=\"std-setting-TEST_TEMPLATE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">TEMPLATE</span></code><a class=\"heading-anchor\" href=\"#template\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>这是 PostgreSQL 特有的配置。</p>\n<p><a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/sql-createdatabase.html\">template</a> 的名称（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">'template0'</span></code>），用于创建测试数据库。</p>\n</section>\n<section id=\"create-db\">\n<span id=\"std-setting-TEST_CREATE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE_DB</span></code><a class=\"heading-anchor\" href=\"#create-db\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>，测试表空间不会在测试开始时自动创建，也不会在测试结束时删除。</p>\n</section>\n<section id=\"create-user\">\n<span id=\"std-setting-TEST_USER_CREATE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">CREATE_USER</span></code><a class=\"heading-anchor\" href=\"#create-user\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>，测试用户不会在测试开始时自动创建，也不会在测试结束时删除。</p>\n</section>\n<section id=\"std-setting-TEST_USER\">\n<span id=\"id4\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">USER</span></code><a class=\"heading-anchor\" href=\"#std-setting-TEST_USER\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>连接到 Oracle 数据库时使用的用户名。如果没有提供，Django 将使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">'test_'</span> <span class=\"pre\">+</span> <span class=\"pre\">USER</span></code>。</p>\n</section>\n<section id=\"std-setting-TEST_PASSWD\">\n<span id=\"id5\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">PASSWORD</span></code><a class=\"heading-anchor\" href=\"#std-setting-TEST_PASSWD\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>连接到 Oracle 数据库时使用的密码。如果没有提供，Django 会随机生成一个密码。</p>\n</section>\n<section id=\"oracle-managed-files\">\n<span id=\"std-setting-TEST_ORACLE_MANAGED_FILES\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">ORACLE_MANAGED_FILES</span></code><a class=\"heading-anchor\" href=\"#oracle-managed-files\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p><a class=\"reference internal\" href=\"#std-setting-DATAFILE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATAFILE</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-DATAFILE_TMP\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATAFILE_TMP</span></code></a> 将被忽略。</p>\n</section>\n<section id=\"tblspace\">\n<span id=\"std-setting-TEST_TBLSPACE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">TBLSPACE</span></code><a class=\"heading-anchor\" href=\"#tblspace\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>运行测试时使用的表空间的名称。如果没有提供，Django 将使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">'test_'</span> <span class=\"pre\">+</span> <span class=\"pre\">USER</span></code>。</p>\n</section>\n<section id=\"tblspace-tmp\">\n<span id=\"std-setting-TEST_TBLSPACE_TMP\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">TBLSPACE_TMP</span></code><a class=\"heading-anchor\" href=\"#tblspace-tmp\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>运行测试时使用的临时表空间的名称。如果没有提供，Django 将使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">'test_'</span> <span class=\"pre\">+</span> <span class=\"pre\">USER</span> <span class=\"pre\">+</span> <span class=\"pre\">'_temp'</span></code>。</p>\n</section>\n<section id=\"datafile\">\n<span id=\"std-setting-DATAFILE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">DATAFILE</span></code><a class=\"heading-anchor\" href=\"#datafile\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>TBLSPACE 要使用的数据文件名。如果没有提供，Django 将使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">TBLSPACE</span> <span class=\"pre\">+</span> <span class=\"pre\">'.dbf'</span></code>。</p>\n</section>\n<section id=\"datafile-tmp\">\n<span id=\"std-setting-DATAFILE_TMP\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">DATAFILE_TMP</span></code><a class=\"heading-anchor\" href=\"#datafile-tmp\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>TBLSPACE_TMP 的数据文件名。如果没有提供，Django 将使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">TBLSPACE_TMP</span> <span class=\"pre\">+</span> <span class=\"pre\">'.dbf'</span></code>。</p>\n</section>\n<section id=\"datafile-maxsize\">\n<span id=\"std-setting-DATAFILE_MAXSIZE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">DATAFILE_MAXSIZE</span></code><a class=\"heading-anchor\" href=\"#datafile-maxsize\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'500M'</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>DATAFILE 允许增长的最大尺寸。</p>\n</section>\n<section id=\"datafile-tmp-maxsize\">\n<span id=\"std-setting-DATAFILE_TMP_MAXSIZE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">DATAFILE_TMP_MAXSIZE</span></code><a class=\"heading-anchor\" href=\"#datafile-tmp-maxsize\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'500M'</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>DATAFILE_TMP 允许增长的最大尺寸。</p>\n</section>\n<section id=\"datafile-size\">\n<span id=\"std-setting-DATAFILE_SIZE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">DATAFILE_SIZE</span></code><a class=\"heading-anchor\" href=\"#datafile-size\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'50M'</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>DATAFILE 的初始大小。</p>\n</section>\n<section id=\"datafile-tmp-size\">\n<span id=\"std-setting-DATAFILE_TMP_SIZE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">DATAFILE_TMP_SIZE</span></code><a class=\"heading-anchor\" href=\"#datafile-tmp-size\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'50M'</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>DATAFILE_TMP 的初始大小。</p>\n</section>\n<section id=\"datafile-extsize\">\n<span id=\"std-setting-DATAFILE_EXTSIZE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">DATAFILE_EXTSIZE</span></code><a class=\"heading-anchor\" href=\"#datafile-extsize\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'25M'</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>当需要更多空间时，DATAFILE 的扩展量。</p>\n</section>\n<section id=\"datafile-tmp-extsize\">\n<span id=\"std-setting-DATAFILE_TMP_EXTSIZE\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">DATAFILE_TMP_EXTSIZE</span></code><a class=\"heading-anchor\" href=\"#datafile-tmp-extsize\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'25M'</span></code></p>\n<p>这是 Oracle 特有的配置。</p>\n<p>当需要更多空间时，DATAFILE_TMP 的扩展量。</p>\n</section>\n</section>\n</section>\n<section id=\"data-upload-max-memory-size\">\n<span id=\"std-setting-DATA_UPLOAD_MAX_MEMORY_SIZE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DATA_UPLOAD_MAX_MEMORY_SIZE</span></code><a class=\"heading-anchor\" href=\"#data-upload-max-memory-size\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">2621440</span></code> （即 2.5 MB）。</p>\n<p>The maximum size in bytes that a request body may be before a\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/exceptions/#django.core.exceptions.SuspiciousOperation\" title=\"django.core.exceptions.SuspiciousOperation\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">SuspiciousOperation</span></code></a> (<code class=\"docutils literal notranslate\"><span class=\"pre\">RequestDataTooBig</span></code>) is\nraised. The check is done when accessing <code class=\"docutils literal notranslate\"><span class=\"pre\">request.body</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">request.POST</span></code>\nand is calculated against the total request size excluding any file upload\ndata (<code class=\"docutils literal notranslate\"><span class=\"pre\">request.FILES</span></code>). You can set this to <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> to disable the check.\nApplications that are expected to receive unusually large form posts should\ntune this setting.</p>\n<p>Under ASGI, the entire request may be spooled to disk before this limit is\nenforced. Therefore, it is strongly recommended to place additional protections\nin front of Django which limit the entire request payload.</p>\n<p>The amount of request data is correlated to the amount of memory or storage\nneeded to process the request and populate the GET and POST dictionaries.\nLarge requests could be used as a denial-of-service attack vector if left\nunchecked. Since web servers don't typically perform deep request inspection,\nit's not possible to perform a similar check at that level.</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-FILE_UPLOAD_MAX_MEMORY_SIZE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_MAX_MEMORY_SIZE</span></code></a>。</p>\n</section>\n<section id=\"data-upload-max-number-fields\">\n<span id=\"std-setting-DATA_UPLOAD_MAX_NUMBER_FIELDS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DATA_UPLOAD_MAX_NUMBER_FIELDS</span></code><a class=\"heading-anchor\" href=\"#data-upload-max-number-fields\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">1000</span></code></p>\n<p>在发生 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/exceptions/#django.core.exceptions.SuspiciousOperation\" title=\"django.core.exceptions.SuspiciousOperation\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">SuspiciousOperation</span></code></a> （<code class=\"docutils literal notranslate\"><span class=\"pre\">TooManyFields</span></code>）之前，可以通过 GET 或 POST 接收到的参数的最大数量。你可以将其设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> 来禁用该检查。预计会收到异常多的表单字段的应用程序应该调整这个配置。</p>\n<p>请求参数的数量与处理请求和填充 GET 和 POST 字典所需的时间有关。如果不加以检查，大的请求可能会被用作拒绝服务攻击的载体。由于 Web 服务器通常不会进行深层的请求检查，所以不可能在这个层面进行类似的检查。</p>\n</section>\n<section id=\"data-upload-max-number-files\">\n<span id=\"std-setting-DATA_UPLOAD_MAX_NUMBER_FILES\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DATA_UPLOAD_MAX_NUMBER_FILES</span></code><a class=\"heading-anchor\" href=\"#data-upload-max-number-files\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">100</span></code></p>\n<p>在使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">multipart/form-data</span></code> 编码的请求中，可以通过 POST 接收的文件的最大数量，在引发 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/exceptions/#django.core.exceptions.SuspiciousOperation\" title=\"django.core.exceptions.SuspiciousOperation\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">SuspiciousOperation</span></code></a> （<code class=\"docutils literal notranslate\"><span class=\"pre\">TooManyFiles</span></code>）之前。你可以将其设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> 以禁用此检查。预计会接收到异常多的文件字段的应用程序应调整此设置。</p>\n<p>接受的文件数量与处理请求所需的时间和内存量相关联。如果不加以检查，大型请求可能会被用作拒绝服务攻击的矢量。由于 Web 服务器通常不执行深度请求检查，因此在该级别不可能执行类似的检查。</p>\n</section>\n<section id=\"database-routers\">\n<span id=\"std-setting-DATABASE_ROUTERS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DATABASE_ROUTERS</span></code><a class=\"heading-anchor\" href=\"#database-routers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>在执行数据库查询时，将用于确定使用哪个数据库的路由器列表。</p>\n<p>参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/db/multi-db/#topics-db-multi-db-routing\"><span class=\"std std-ref\">多数据库配置中的自动数据库路由</span></a> 的文档。</p>\n</section>\n<section id=\"date-format\">\n<span id=\"std-setting-DATE_FORMAT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DATE_FORMAT</span></code><a class=\"heading-anchor\" href=\"#date-format\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'N</span> <span class=\"pre\">j,</span> <span class=\"pre\">Y'</span></code> （例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">Feb.</span> <span class=\"pre\">4,</span> <span class=\"pre\">2003</span></code>）</p>\n<p>在系统的任何部分中用于显示日期字段的默认格式化方式。请注意，由语言环境规定的格式具有更高的优先级，将被应用于显示。请参阅 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">allowed</span> <span class=\"pre\">date</span> <span class=\"pre\">format</span> <span class=\"pre\">strings</span></code></a>。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_FORMAT</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-TIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_FORMAT</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-SHORT_DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SHORT_DATE_FORMAT</span></code></a>。</p>\n</section>\n<section id=\"date-input-formats\">\n<span id=\"std-setting-DATE_INPUT_FORMATS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DATE_INPUT_FORMATS</span></code><a class=\"heading-anchor\" href=\"#date-input-formats\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">[</span>\n    <span class=\"s2\">&quot;%Y-%m-</span><span class=\"si\">%d</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;2006-10-25&#39;</span>\n    <span class=\"s2\">&quot;%m/</span><span class=\"si\">%d</span><span class=\"s2\">/%Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;10/25/2006&#39;</span>\n    <span class=\"s2\">&quot;%m/</span><span class=\"si\">%d</span><span class=\"s2\">/%y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;10/25/06&#39;</span>\n    <span class=\"s2\">&quot;%b </span><span class=\"si\">%d</span><span class=\"s2\"> %Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;Oct 25 2006&#39;</span>\n    <span class=\"s2\">&quot;%b </span><span class=\"si\">%d</span><span class=\"s2\">, %Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;Oct 25, 2006&#39;</span>\n    <span class=\"s2\">&quot;</span><span class=\"si\">%d</span><span class=\"s2\"> %b %Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;25 Oct 2006&#39;</span>\n    <span class=\"s2\">&quot;</span><span class=\"si\">%d</span><span class=\"s2\"> %b, %Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;25 Oct, 2006&#39;</span>\n    <span class=\"s2\">&quot;%B </span><span class=\"si\">%d</span><span class=\"s2\"> %Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;October 25 2006&#39;</span>\n    <span class=\"s2\">&quot;%B </span><span class=\"si\">%d</span><span class=\"s2\">, %Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;October 25, 2006&#39;</span>\n    <span class=\"s2\">&quot;</span><span class=\"si\">%d</span><span class=\"s2\"> %B %Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;25 October 2006&#39;</span>\n    <span class=\"s2\">&quot;</span><span class=\"si\">%d</span><span class=\"s2\"> %B, %Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;25 October, 2006&#39;</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>在日期字段上输入数据时接受的格式列表。格式将按顺序被尝试，使用第一个有效的格式。注意这些格式字符串使用 Python 的 <a class=\"reference external\" href=\"https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior\" title=\"(in Python v3.14)\"><span class=\"xref std std-ref\">datetime 模块语法</span></a>，而不是来自 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">date</span></code></a> 模板过滤器的格式字符串。</p>\n<p>由区域设置规定的格式具有更高的优先级，将会被应用。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DATETIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_INPUT_FORMATS</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-TIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_INPUT_FORMATS</span></code></a>。</p>\n</section>\n<section id=\"datetime-format\">\n<span id=\"std-setting-DATETIME_FORMAT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DATETIME_FORMAT</span></code><a class=\"heading-anchor\" href=\"#datetime-format\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'N</span> <span class=\"pre\">j,</span> <span class=\"pre\">Y,</span> <span class=\"pre\">P'</span></code> （例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">Feb.</span> <span class=\"pre\">4,</span> <span class=\"pre\">2003,</span> <span class=\"pre\">4</span> <span class=\"pre\">p.m.</span></code>）</p>\n<p>在系统的任何部分显示日期时间字段时要使用的默认格式。请注意，由区域设置规定的格式具有更高的优先级，将会被应用。请参阅 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">allowed</span> <span class=\"pre\">date</span> <span class=\"pre\">format</span> <span class=\"pre\">strings</span></code></a>。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_FORMAT</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-TIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_FORMAT</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-SHORT_DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SHORT_DATETIME_FORMAT</span></code></a>。</p>\n</section>\n<section id=\"datetime-input-formats\">\n<span id=\"std-setting-DATETIME_INPUT_FORMATS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DATETIME_INPUT_FORMATS</span></code><a class=\"heading-anchor\" href=\"#datetime-input-formats\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">[</span>\n    <span class=\"s2\">&quot;%Y-%m-</span><span class=\"si\">%d</span><span class=\"s2\"> %H:%M:%S&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;2006-10-25 14:30:59&#39;</span>\n    <span class=\"s2\">&quot;%Y-%m-</span><span class=\"si\">%d</span><span class=\"s2\"> %H:%M:%S.</span><span class=\"si\">%f</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;2006-10-25 14:30:59.000200&#39;</span>\n    <span class=\"s2\">&quot;%Y-%m-</span><span class=\"si\">%d</span><span class=\"s2\"> %H:%M&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;2006-10-25 14:30&#39;</span>\n    <span class=\"s2\">&quot;%m/</span><span class=\"si\">%d</span><span class=\"s2\">/%Y %H:%M:%S&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;10/25/2006 14:30:59&#39;</span>\n    <span class=\"s2\">&quot;%m/</span><span class=\"si\">%d</span><span class=\"s2\">/%Y %H:%M:%S.</span><span class=\"si\">%f</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;10/25/2006 14:30:59.000200&#39;</span>\n    <span class=\"s2\">&quot;%m/</span><span class=\"si\">%d</span><span class=\"s2\">/%Y %H:%M&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;10/25/2006 14:30&#39;</span>\n    <span class=\"s2\">&quot;%m/</span><span class=\"si\">%d</span><span class=\"s2\">/%y %H:%M:%S&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;10/25/06 14:30:59&#39;</span>\n    <span class=\"s2\">&quot;%m/</span><span class=\"si\">%d</span><span class=\"s2\">/%y %H:%M:%S.</span><span class=\"si\">%f</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;10/25/06 14:30:59.000200&#39;</span>\n    <span class=\"s2\">&quot;%m/</span><span class=\"si\">%d</span><span class=\"s2\">/%y %H:%M&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;10/25/06 14:30&#39;</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>在日期时间字段上输入数据时可接受的格式列表。格式将按顺序被尝试，使用第一个有效的格式。注意这些格式字符串使用 Python 的 <a class=\"reference external\" href=\"https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior\" title=\"(in Python v3.14)\"><span class=\"xref std std-ref\">datetime 模块语法</span></a>，而不是 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">date</span></code></a> 模板过滤器的格式字符串。纯日期格式不包括在内，因为日期时间字段会在最后时刻自动尝试 <a class=\"reference internal\" href=\"#std-setting-DATE_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_INPUT_FORMATS</span></code></a>。</p>\n<p>由区域设置规定的格式具有更高的优先级，将会被应用。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DATE_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_INPUT_FORMATS</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-TIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_INPUT_FORMATS</span></code></a>。</p>\n</section>\n<section id=\"debug\">\n<span id=\"std-setting-DEBUG\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code><a class=\"heading-anchor\" href=\"#debug\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>一个开启、关闭调试模式的布尔值。</p>\n<p>永远不要在 <a class=\"reference internal\" href=\"#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> 开启的情况下将网站部署到生产中。</p>\n<p>调试模式的主要功能之一是显示详细的错误页面。如果你的应用程序在 <a class=\"reference internal\" href=\"#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> 为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> 时引发了异常，Django 会显示一个详细的回溯，包括很多关于你的环境的元数据，比如所有当前定义的 Django 配置（来自 <code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code>）。</p>\n<p>作为一项安全措施，Django将 <em>不</em> 包含可能是敏感的配置，如 <a class=\"reference internal\" href=\"#std-setting-SECRET_KEY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code></a>。具体来说，它将排除任何名称中包含以下内容的配置。</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'API'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'KEY'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'PASS'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'SECRET'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'SIGNATURE'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'TOKEN'</span></code></p></li>\n</ul>\n<p>请注意，这些是 <em>部分</em> 匹配。<code class=\"docutils literal notranslate\"><span class=\"pre\">'PASS'</span></code> 也将与 PASSWORD 匹配，正如 <code class=\"docutils literal notranslate\"><span class=\"pre\">'TOKEN'</span></code> 也将与 TOKENIZED 匹配，以此类推。</p>\n<p>不过，请注意，你的调试输出中总会有一些部分是不适合公开的。文件路径、配置选项等都会给攻击者提供关于你的服务器的额外信息。</p>\n<p>同样重要的是，当 <a class=\"reference internal\" href=\"#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> 开启时，Django 会记住它执行的每个 SQL 查询。这在调试时很有用，但在生产服务器上会迅速消耗内存。</p>\n<p>最后，如果 <a class=\"reference internal\" href=\"#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> 为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>，还需要正确设置 <a class=\"reference internal\" href=\"#std-setting-ALLOWED_HOSTS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ALLOWED_HOSTS</span></code></a> 配置。否则，所有的请求都会以 “Bad Request (400) ” 返回。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>默认的 <code class=\"file docutils literal notranslate\"><span class=\"pre\">settings.py</span></code> 文件由 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">django-admin</span> <span class=\"pre\">startproject</span></code></a> 创建，为了方便，设置 <code class=\"docutils literal notranslate\"><span class=\"pre\">DEBUG</span> <span class=\"pre\">=</span> <span class=\"pre\">True</span></code>。</p>\n</aside>\n</section>\n<section id=\"debug-propagate-exceptions\">\n<span id=\"std-setting-DEBUG_PROPAGATE_EXCEPTIONS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DEBUG_PROPAGATE_EXCEPTIONS</span></code><a class=\"heading-anchor\" href=\"#debug-propagate-exceptions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，则跳过 Django 对视图函数的异常处理（<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/urls/#django.conf.urls.handler500\" title=\"django.conf.urls.handler500\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">handler500</span></code></a>，或者如果 <a class=\"reference internal\" href=\"#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> 为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> 则使用调试视图），以及对 500 响应的日志记录（<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/logging/#django-request-logger\"><span class=\"std std-ref\">django.request</span></a>），异常会向上传播。</p>\n<p>这对于一些测试配置是有用的。除非你想让你的 web 服务器（而不是 Django）生成“内部服务器错误”的响应，否则它不应该被用于实时站点。在这种情况下，确保你的服务器不会在响应中显示堆栈跟踪或其他敏感信息。</p>\n</section>\n<section id=\"decimal-separator\">\n<span id=\"std-setting-DECIMAL_SEPARATOR\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DECIMAL_SEPARATOR</span></code><a class=\"heading-anchor\" href=\"#decimal-separator\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'.'</span></code> （点）</p>\n<p>格式化小数时使用的默认小数分隔符。</p>\n<p>请注意，由区域设置规定的格式具有更高的优先级，将会被应用。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-NUMBER_GROUPING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NUMBER_GROUPING</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">THOUSAND_SEPARATOR</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-USE_THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_THOUSAND_SEPARATOR</span></code></a>。</p>\n</section>\n<section id=\"default-auto-field\">\n<span id=\"std-setting-DEFAULT_AUTO_FIELD\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DEFAULT_AUTO_FIELD</span></code><a class=\"heading-anchor\" href=\"#default-auto-field\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Default: <code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/models/fields/#django.db.models.BigAutoField\" title=\"django.db.models.BigAutoField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.db.models.BigAutoField</span></code></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code></p>\n<p>默认的主键字段类型，用于没有带有 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/models/fields/#django.db.models.Field.primary_key\" title=\"django.db.models.Field.primary_key\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">primary_key=True</span></code></a> 字段的模型。</p>\n<aside class=\"version-note version-changed\" data-version=\"6.0\">\n<p class=\"version-note-title\">Changed in Django 6.0</p><p>In older versions, the default value is\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/models/fields/#django.db.models.AutoField\" title=\"django.db.models.AutoField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.db.models.AutoField</span></code></a>.</p>\n</aside>\n<aside class=\"admonition-migrating-auto-created-through-tables admonition\">\n<p class=\"admonition-title\">迁移自动创建的中间表</p>\n<p>当为多对多关系创建新的自动创建的中间表时，将尊重 <code class=\"docutils literal notranslate\"><span class=\"pre\">DEFAULT_AUTO_FIELD</span></code> 的值。</p>\n<p>不幸的是，现有的自动创建的中间表的主键目前不能被迁移框架所更新。</p>\n<p>这意味着，如果你切换了 <code class=\"docutils literal notranslate\"><span class=\"pre\">DEFAULT_AUTO_FIELD</span></code> 的值，然后生成迁移，相关模型的主键将被更新，来自中间表的外键也将被更新，但是自动创建的中间表的主键将不会被迁移。</p>\n<p>为了解决这个问题，你应该在你的迁移中添加一个 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/migration-operations/#django.db.migrations.operations.RunSQL\" title=\"django.db.migrations.operations.RunSQL\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RunSQL</span></code></a> 操作来执行所需的 <code class=\"docutils literal notranslate\"><span class=\"pre\">ALTER</span> <span class=\"pre\">TABLE</span></code> 步骤。你可以通过 <code class=\"docutils literal notranslate\"><span class=\"pre\">sqlmigrate</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">dbshell</span></code> 或字段的 <code class=\"docutils literal notranslate\"><span class=\"pre\">remote_field.through._meta.db_table</span></code> 属性来检查现有的表名。</p>\n<p>通过模型明确定义的，已经由迁移系统处理。</p>\n<p>允许对现有的自动创建的中间表的主键进行自动迁移 <a class=\"extlink-ticket reference external\" href=\"https://code.djangoproject.com/ticket/32674\">可能会在以后实现</a>。</p>\n</aside>\n</section>\n<section id=\"default-charset\">\n<span id=\"std-setting-DEFAULT_CHARSET\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DEFAULT_CHARSET</span></code><a class=\"heading-anchor\" href=\"#default-charset\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'utf-8'</span></code></p>\n<p>如果没有手动指定 MIME 类型，所有 <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpResponse</span></code> 对象将使用默认字符集。在构建 <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Type</span></code> 头时使用。</p>\n</section>\n<section id=\"default-exception-reporter\">\n<span id=\"std-setting-DEFAULT_EXCEPTION_REPORTER\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DEFAULT_EXCEPTION_REPORTER</span></code><a class=\"heading-anchor\" href=\"#default-exception-reporter\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/howto/error-reporting/#django.views.debug.ExceptionReporter\" title=\"django.views.debug.ExceptionReporter\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.views.debug.ExceptionReporter</span></code></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code></p>\n<p>如果还没有为 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/request-response/#django.http.HttpRequest\" title=\"django.http.HttpRequest\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code></a> 实例分配任何异常报告类，则使用默认的异常报告类。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/error-reporting/#custom-error-reports\"><span class=\"std std-ref\">自定义错误报告</span></a>。</p>\n</section>\n<section id=\"default-exception-reporter-filter\">\n<span id=\"std-setting-DEFAULT_EXCEPTION_REPORTER_FILTER\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code><a class=\"heading-anchor\" href=\"#default-exception-reporter-filter\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/howto/error-reporting/#django.views.debug.SafeExceptionReporterFilter\" title=\"django.views.debug.SafeExceptionReporterFilter\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.views.debug.SafeExceptionReporterFilter</span></code></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code></p>\n<p>如果还没有为 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/request-response/#django.http.HttpRequest\" title=\"django.http.HttpRequest\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code></a> 实例分配任何异常报告过滤类，则使用默认的异常报告过滤类。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/error-reporting/#filtering-error-reports\"><span class=\"std std-ref\">过滤错误报告</span></a>。</p>\n</section>\n<section id=\"default-from-email\">\n<span id=\"std-setting-DEFAULT_FROM_EMAIL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DEFAULT_FROM_EMAIL</span></code><a class=\"heading-anchor\" href=\"#default-from-email\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'webmaster&#64;localhost'</span></code></p>\n<p>默认电子邮件地址用于网站管理员的自动通信。此地址用于发送电子邮件的 <code class=\"docutils literal notranslate\"><span class=\"pre\">From:</span></code> 头，并且可以采用所选电子邮件发送协议中有效的任何格式。</p>\n<p>这不会影响发送给 <a class=\"reference internal\" href=\"#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code></a> 的错误消息。有关此事，请参阅 <a class=\"reference internal\" href=\"#std-setting-SERVER_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SERVER_EMAIL</span></code></a>。</p>\n<p>To build an address with a display name from variable content, see\n<a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#formatting-addresses\"><span class=\"std std-ref\">Formatting email addresses</span></a>.</p>\n</section>\n<section id=\"default-index-tablespace\">\n<span id=\"std-setting-DEFAULT_INDEX_TABLESPACE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DEFAULT_INDEX_TABLESPACE</span></code><a class=\"heading-anchor\" href=\"#default-index-tablespace\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>如果后端支持的话，在没有指定索引的字段上使用的默认表空间（参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/db/tablespaces/\"><span class=\"doc\">表空间（Tablespaces）</span></a>）。</p>\n</section>\n<section id=\"default-tablespace\">\n<span id=\"std-setting-DEFAULT_TABLESPACE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DEFAULT_TABLESPACE</span></code><a class=\"heading-anchor\" href=\"#default-tablespace\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>对于没有指定表空间的模型，如果后端支持，则使用默认表空间（参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/db/tablespaces/\"><span class=\"doc\">表空间（Tablespaces）</span></a>）。</p>\n</section>\n<section id=\"disallowed-user-agents\">\n<span id=\"std-setting-DISALLOWED_USER_AGENTS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">DISALLOWED_USER_AGENTS</span></code><a class=\"heading-anchor\" href=\"#disallowed-user-agents\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>编译后的正则表达式对象列表，代表全系统范围内不允许访问任何页面的 User-Agent 字符串。用于机器人／爬虫。只有在安装了 <code class=\"docutils literal notranslate\"><span class=\"pre\">CommonMiddleware</span></code> 的情况下才会使用（参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/middleware/\"><span class=\"doc\">中间件</span></a>）。</p>\n</section>\n<section id=\"email-backend\">\n<span id=\"std-setting-EMAIL_BACKEND\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_BACKEND</span></code><a class=\"heading-anchor\" href=\"#email-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Default: <code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#topic-email-smtp-backend\"><span class=\"std std-ref\">django.core.mail.backends.smtp.EmailBackend</span></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code></p>\n<p>用于发送电子邮件的后端。关于可用的后端列表，请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#topic-email-backends\"><span class=\"std std-ref\">邮件后端</span></a>。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <a class=\"reference internal\" href=\"#std-setting-MAILERS-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code></a> in the\n<a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;default&quot;</span></code> configuration. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-file-path\">\n<span id=\"std-setting-EMAIL_FILE_PATH\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_FILE_PATH</span></code><a class=\"heading-anchor\" href=\"#email-file-path\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：未定义</p>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#topic-email-file-backend\"><span class=\"std std-ref\">文件邮件后端</span></a> 用来存储输出文件的目录。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;file_path&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a>\nin a <a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the file email backend. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-host\">\n<span id=\"std-setting-EMAIL_HOST\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST</span></code><a class=\"heading-anchor\" href=\"#email-host\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'localhost'</span></code></p>\n<p>用于发送电子邮件的主机。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-EMAIL_PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_PORT</span></code></a>。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;host&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> in a\n<a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the SMTP email backend. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-host-password\">\n<span id=\"std-setting-EMAIL_HOST_PASSWORD\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST_PASSWORD</span></code><a class=\"heading-anchor\" href=\"#email-host-password\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>在 <a class=\"reference internal\" href=\"#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST</span></code></a> 中定义的 SMTP 服务器使用的密码。这个配置和 <a class=\"reference internal\" href=\"#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST_USER</span></code></a> 中的密码一起使用。如果这两个配置中的任何一个为空，Django 就不会尝试验证。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST_USER</span></code></a>。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;password&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> in\na <a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the SMTP email backend. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-host-user\">\n<span id=\"std-setting-EMAIL_HOST_USER\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST_USER</span></code><a class=\"heading-anchor\" href=\"#email-host-user\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>在 <a class=\"reference internal\" href=\"#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST</span></code></a> 中定义的 SMTP 服务器的用户名。如果为空，Django 将不会尝试认证。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-EMAIL_HOST_PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST_PASSWORD</span></code></a>。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;username&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> in\na <a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the SMTP email backend. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-port\">\n<span id=\"std-setting-EMAIL_PORT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_PORT</span></code><a class=\"heading-anchor\" href=\"#email-port\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">25</span></code></p>\n<p>在 :setting:<a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>EMAIL_HOST' 中定义的 SMTP 服务器使用的端口。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;port&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> in a\n<a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the SMTP email backend. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-subject-prefix\">\n<span id=\"std-setting-EMAIL_SUBJECT_PREFIX\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_SUBJECT_PREFIX</span></code><a class=\"heading-anchor\" href=\"#email-subject-prefix\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'[Django]</span> <span class=\"pre\">'</span></code></p>\n<p>用 <code class=\"docutils literal notranslate\"><span class=\"pre\">django.core.mail.mail_admins</span></code> 或 <code class=\"docutils literal notranslate\"><span class=\"pre\">django.core.mail.mail_managers</span></code> 发送邮件的主题行前缀。你可能会想要包含尾部的空格。</p>\n</section>\n<section id=\"email-use-localtime\">\n<span id=\"std-setting-EMAIL_USE_LOCALTIME\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_LOCALTIME</span></code><a class=\"heading-anchor\" href=\"#email-use-localtime\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否以当地时区（<code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>）或 UTC（<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>）发送 SMTP <code class=\"docutils literal notranslate\"><span class=\"pre\">Date</span></code> 邮件头。</p>\n</section>\n<section id=\"email-use-tls\">\n<span id=\"std-setting-EMAIL_USE_TLS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_TLS</span></code><a class=\"heading-anchor\" href=\"#email-use-tls\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>与 SMTP 服务器对话时是否使用 TLS（安全）连接。这用于显式 TLS 连接，一般在 587 端口。如果你遇到挂起的连接，请查看隐式 TLS 配置 <a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_SSL</span></code></a>。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;use_tls&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> in\na <a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the SMTP email backend. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-use-ssl\">\n<span id=\"std-setting-EMAIL_USE_SSL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_SSL</span></code><a class=\"heading-anchor\" href=\"#email-use-ssl\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>与 SMTP 服务器对话时是否使用隐式 TLS（安全）连接。在大多数电子邮件文档中，这种类型的 TLS 连接被称为 SSL。它通常在 465 端口使用。如果你遇到问题，请查看显式 TLS 配置 <a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_TLS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_TLS</span></code></a>。</p>\n<p>注意 <a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_TLS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_TLS</span></code></a> ／ <a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_SSL</span></code></a> 是相互排斥的，所以只能将其中一个设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;use_ssl&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> in\na <a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the SMTP email backend. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-ssl-certfile\">\n<span id=\"std-setting-EMAIL_SSL_CERTFILE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_SSL_CERTFILE</span></code><a class=\"heading-anchor\" href=\"#email-ssl-certfile\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>If <a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_SSL</span></code></a> or <a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_TLS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_TLS</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> and the\nsecure connection to the SMTP server requires client authentication, use this\nsetting to specify the path to a PEM-formatted certificate chain file, which\nmust be used in conjunction with <a class=\"reference internal\" href=\"#std-setting-EMAIL_SSL_KEYFILE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_SSL_KEYFILE</span></code></a>.</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_SSL_CERTFILE</span></code> should not be used with a self-signed server certificate\nor a certificate from a private certificate authority (CA). In such cases, the\nserver's certificate (or the root certificate of the private CA) should be\ninstalled into the system's CA bundle. This can be done by following\nplatform-specific instructions for installing a root CA certificate,\nor by using OpenSSL's <code class=\"docutils literal notranslate\"><span class=\"pre\">SSL_CERT_FILE</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">SSL_CERT_DIR</span></code> environment\nvariables to specify a custom certificate bundle (if modifying the system\nbundle is not possible or desired).</p>\n<p>For more complex scenarios, the <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#topic-email-smtp-backend\"><span class=\"std std-ref\">SMTP EmailBackend</span></a> can be subclassed to add root certificates to its\n<code class=\"docutils literal notranslate\"><span class=\"pre\">ssl_context</span></code> using\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/ssl.html#ssl.SSLContext.load_verify_locations\" title=\"(in Python v3.14)\"><code class=\"docutils literal notranslate\"><span class=\"pre\">ssl.SSLContext.load_verify_locations()</span></code></a>.</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;ssl_certfile&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> in a <a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the SMTP\nemail backend. See <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-ssl-keyfile\">\n<span id=\"std-setting-EMAIL_SSL_KEYFILE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_SSL_KEYFILE</span></code><a class=\"heading-anchor\" href=\"#email-ssl-keyfile\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>If <a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_SSL</span></code></a> or <a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_TLS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_TLS</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, you can\noptionally specify the path to a PEM-formatted private key file for client\nauthentication of the SSL connection along with <a class=\"reference internal\" href=\"#std-setting-EMAIL_SSL_CERTFILE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_SSL_CERTFILE</span></code></a>.</p>\n<p>请注意，设置 <a class=\"reference internal\" href=\"#std-setting-EMAIL_SSL_CERTFILE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_SSL_CERTFILE</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-EMAIL_SSL_KEYFILE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_SSL_KEYFILE</span></code></a> 不会导致任何证书检查。它们被传递给底层的 SSL 连接。有关证书链文件和私钥文件的处理方式的详细信息，请参阅 Python 的 <a class=\"reference external\" href=\"https://docs.python.org/3/library/ssl.html#ssl.SSLContext.wrap_socket\" title=\"(in Python v3.14)\"><code class=\"docutils literal notranslate\"><span class=\"pre\">ssl.SSLContext.wrap_socket()</span></code></a> 函数的文档。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;ssl_keyfile&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a>\nin a <a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the SMTP email backend. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"email-timeout\">\n<span id=\"std-setting-EMAIL_TIMEOUT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_TIMEOUT</span></code><a class=\"heading-anchor\" href=\"#email-timeout\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>指定阻止连接尝试等操作的超时时间，以秒为单位。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting is deprecated and will be removed in Django 7.0. Its\nreplacement is <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;timeout&quot;</span></code> under <a class=\"reference internal\" href=\"#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code></a> in\na <a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a> definition that uses the SMTP email backend. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</section>\n<section id=\"file-upload-handlers\">\n<span id=\"std-setting-FILE_UPLOAD_HANDLERS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_HANDLERS</span></code><a class=\"heading-anchor\" href=\"#file-upload-handlers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">[</span>\n    <span class=\"s2\">&quot;django.core.files.uploadhandler.MemoryFileUploadHandler&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.core.files.uploadhandler.TemporaryFileUploadHandler&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>上传过程中使用的处理程序列表。改变这个配置可以完全自定义——甚至替换——Django 的上传过程。</p>\n<p>See <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/file-uploads/#file-upload-handlers\"><span class=\"std std-ref\">上传 Handlers</span></a> for details.</p>\n</section>\n<section id=\"file-upload-max-memory-size\">\n<span id=\"std-setting-FILE_UPLOAD_MAX_MEMORY_SIZE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_MAX_MEMORY_SIZE</span></code><a class=\"heading-anchor\" href=\"#file-upload-max-memory-size\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">2621440</span></code> （即 2.5 MB）。</p>\n<p>The maximum size (in bytes) that an upload will be before it gets streamed to\nthe file system. See <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/file-uploads/#file-upload-handlers\"><span class=\"std std-ref\">上传 Handlers</span></a> for details.</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DATA_UPLOAD_MAX_MEMORY_SIZE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATA_UPLOAD_MAX_MEMORY_SIZE</span></code></a>。</p>\n</section>\n<section id=\"file-upload-directory-permissions\">\n<span id=\"std-setting-FILE_UPLOAD_DIRECTORY_PERMISSIONS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_DIRECTORY_PERMISSIONS</span></code><a class=\"heading-anchor\" href=\"#file-upload-directory-permissions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>适用于上传文件过程中创建的目录的数字模式。</p>\n<p>当使用 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> 管理命令时，这个配置也决定了收集的静态目录的默认权限。覆盖它的细节请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a>。</p>\n<p>这个值反映了 <a class=\"reference internal\" href=\"#std-setting-FILE_UPLOAD_PERMISSIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_PERMISSIONS</span></code></a> 配置的功能和注意事项。</p>\n</section>\n<section id=\"file-upload-permissions\">\n<span id=\"std-setting-FILE_UPLOAD_PERMISSIONS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_PERMISSIONS</span></code><a class=\"heading-anchor\" href=\"#file-upload-permissions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">0o644</span></code></p>\n<p>设置新上传文件的数字模式（即 <code class=\"docutils literal notranslate\"><span class=\"pre\">0o644</span></code>）。关于这些模式的更多信息，请参见 <a class=\"reference external\" href=\"https://docs.python.org/3/library/os.html#os.chmod\" title=\"(in Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">os.chmod()</span></code></a> 的文档。</p>\n<p>如果 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，你会得到操作系统依赖的行为。在大多数平台上，临时文件的模式为 <code class=\"docutils literal notranslate\"><span class=\"pre\">0o600</span></code>，从内存中保存的文件将使用系统的标准 umask 保存。</p>\n<p>出于安全考虑，这些权限不应用于存储在 <a class=\"reference internal\" href=\"#std-setting-FILE_UPLOAD_TEMP_DIR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_TEMP_DIR</span></code></a> 中的临时文件。</p>\n<p>当使用 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> 管理命令时，这个配置也决定了收集的静态文件的默认权限。覆盖它的细节请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a>。</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p><strong>总是在模式前加上 **`0o`</strong> 。**</p>\n<p>如果你不熟悉文件模式，请注意 <code class=\"docutils literal notranslate\"><span class=\"pre\">0o</span></code> 的前缀是非常重要的：它表示一个八进制数，这就是模式必须被指定的方式。如果你试图使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">644</span></code>，你会得到完全错误的行为。</p>\n</aside>\n<aside class=\"admonition-a-numeric-value-trumps-umask admonition\">\n<p class=\"admonition-title\">A numeric value trumps umask</p>\n<p>When this setting has a numeric value (one you've set yourself, or the\ndefault <code class=\"docutils literal notranslate\"><span class=\"pre\">0o644</span></code>), this value will be used as is, and a umask will not\nbe applied to it. The umask will apply only if this setting is <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>.</p>\n</aside>\n</section>\n<section id=\"file-upload-temp-dir\">\n<span id=\"std-setting-FILE_UPLOAD_TEMP_DIR\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_TEMP_DIR</span></code><a class=\"heading-anchor\" href=\"#file-upload-temp-dir\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>上传文件时要临时存储数据的目录（一般是大于 <a class=\"reference internal\" href=\"#std-setting-FILE_UPLOAD_MAX_MEMORY_SIZE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_MAX_MEMORY_SIZE</span></code></a> 的文件）。如果 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，Django 将使用操作系统的标准临时目录。例如，在 <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">*</span></a>nix 风格的操作系统上，会默认为 <code class=\"docutils literal notranslate\"><span class=\"pre\">/tmp</span></code>。</p>\n<p>See <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/file-uploads/#file-upload-handlers\"><span class=\"std std-ref\">上传 Handlers</span></a> for details.</p>\n</section>\n<section id=\"first-day-of-week\">\n<span id=\"std-setting-FIRST_DAY_OF_WEEK\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FIRST_DAY_OF_WEEK</span></code><a class=\"heading-anchor\" href=\"#first-day-of-week\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code> （星期日）</p>\n<p>代表一周第一天的数字。这在显示日历时特别有用。该值仅在不使用格式国际化时使用，或者当无法为当前语言环境找到格式时使用。</p>\n<p>该值必须是 0 到 6 的整数，其中 0 代表周日，1 代表周一，以此类推。</p>\n</section>\n<section id=\"fixture-dirs\">\n<span id=\"std-setting-FIXTURE_DIRS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FIXTURE_DIRS</span></code><a class=\"heading-anchor\" href=\"#fixture-dirs\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>除了每个应用程序的 <code class=\"docutils literal notranslate\"><span class=\"pre\">fixtures</span></code> 目录之外，按照搜索顺序列出用于搜索 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/db/fixtures/#fixtures-explanation\"><span class=\"std std-ref\">fixture</span></a> 文件的目录列表。</p>\n<p>请注意，这些路径应该使用 Unix 风格的斜线，即使在 Windows 上也是如此。</p>\n<p>参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/initial-data/#initial-data-via-fixtures\"><span class=\"std std-ref\">使用固定数据提供数据</span></a> 和 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/tools/#topics-testing-fixtures\"><span class=\"std std-ref\">辅助工具加载</span></a>。</p>\n</section>\n<section id=\"force-script-name\">\n<span id=\"std-setting-FORCE_SCRIPT_NAME\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FORCE_SCRIPT_NAME</span></code><a class=\"heading-anchor\" href=\"#force-script-name\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>If not <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>, this will be used as the value of the <code class=\"docutils literal notranslate\"><span class=\"pre\">SCRIPT_NAME</span></code>\nenvironment variable in any HTTP request. This setting can be used to override\nthe server-provided value of <code class=\"docutils literal notranslate\"><span class=\"pre\">SCRIPT_NAME</span></code>, which may be a rewritten version\nof the preferred value or not supplied at all. It is also used by\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/applications/#django.setup\" title=\"django.setup\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">django.setup()</span></code></a> to set the URL resolver script prefix outside of the\nrequest/response cycle (e.g. in management commands and standalone scripts) to\ngenerate correct URLs when <code class=\"docutils literal notranslate\"><span class=\"pre\">FORCE_SCRIPT_NAME</span></code> is provided.</p>\n</section>\n<section id=\"form-renderer\">\n<span id=\"std-setting-FORM_RENDERER\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FORM_RENDERER</span></code><a class=\"heading-anchor\" href=\"#form-renderer\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/forms/renderers/#django.forms.renderers.DjangoTemplates\" title=\"django.forms.renderers.DjangoTemplates\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.forms.renderers.DjangoTemplates</span></code></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code></p>\n<p>用于渲染表单和表单小部件的类。它必须实现 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/forms/renderers/#low-level-widget-render-api\"><span class=\"std std-ref\">低级渲染 API</span></a>。包括的表单渲染器有：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/forms/renderers/#django.forms.renderers.DjangoTemplates\" title=\"django.forms.renderers.DjangoTemplates\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.forms.renderers.DjangoTemplates</span></code></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/forms/renderers/#django.forms.renderers.Jinja2\" title=\"django.forms.renderers.Jinja2\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.forms.renderers.Jinja2</span></code></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/forms/renderers/#django.forms.renderers.TemplatesSetting\" title=\"django.forms.renderers.TemplatesSetting\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.forms.renderers.TemplatesSetting</span></code></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code></p></li>\n</ul>\n</section>\n<section id=\"format-module-path\">\n<span id=\"std-setting-FORMAT_MODULE_PATH\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">FORMAT_MODULE_PATH</span></code><a class=\"heading-anchor\" href=\"#format-module-path\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>一个 Python 包的完整 Python 路径，该 Python 包包含了项目 locale 的自定义格式定义。如果不是 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，Django 将检查当前 locale 目录下的 <code class=\"docutils literal notranslate\"><span class=\"pre\">formats.py</span></code> 文件，并将使用该文件中定义的格式。</p>\n<p>包含格式定义的目录的名称预期应使用 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/#term-locale-name\"><span class=\"xref std std-term\">locale name</span></a> 表示法命名，例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">de</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">pt_BR</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">en_US</span></code> 等。</p>\n<p>例如，如果 <a class=\"reference internal\" href=\"#std-setting-FORMAT_MODULE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FORMAT_MODULE_PATH</span></code></a> 设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">mysite.formats</span></code>，并且当前语言是 <code class=\"docutils literal notranslate\"><span class=\"pre\">en</span></code> （英语），Django 会期望一个类似以下的目录结构：</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>mysite/\n    formats/\n        __init__.py\n        en/\n            __init__.py\n            formats.py\n</code></pre></div>\n<p>你也可以将此设置为 Python 路径列表，例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">FORMAT_MODULE_PATH</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;mysite.formats&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;some_app.formats&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>当 Django 搜索某个格式时，它将通过所有给定的 Python 路径，直到找到一个真正定义该格式的模块。这意味着在列表中较远处的包中定义的格式将优先于较远处的包中的格式。</p>\n<p>可用格式：</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATE_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_INPUT_FORMATS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATETIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_INPUT_FORMATS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DECIMAL_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DECIMAL_SEPARATOR</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-FIRST_DAY_OF_WEEK\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FIRST_DAY_OF_WEEK</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-MONTH_DAY_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MONTH_DAY_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-NUMBER_GROUPING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NUMBER_GROUPING</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SHORT_DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SHORT_DATE_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SHORT_DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SHORT_DATETIME_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">THOUSAND_SEPARATOR</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-TIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-TIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_INPUT_FORMATS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-YEAR_MONTH_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">YEAR_MONTH_FORMAT</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"ignorable-404-urls\">\n<span id=\"std-setting-IGNORABLE_404_URLS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">IGNORABLE_404_URLS</span></code><a class=\"heading-anchor\" href=\"#ignorable-404-urls\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>List of compiled regular expression objects describing URLs that should be\nignored when reporting HTTP 404 errors via email (see\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/error-reporting/\"><span class=\"doc\">如何管理错误报告</span></a>). Regular expressions are matched against\nrequest's full paths, as returned by\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/request-response/#django.http.HttpRequest.get_full_path\" title=\"django.http.HttpRequest.get_full_path\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_full_path()</span></code></a> (including any query strings).\nUse this if your site does not provide a commonly requested file such as\n<code class=\"docutils literal notranslate\"><span class=\"pre\">favicon.ico</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">robots.txt</span></code>.</p>\n<p>只有当 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">BrokenLinkEmailsMiddleware</span></code></a> 被启用时，才会使用这个功能（参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/middleware/\"><span class=\"doc\">中间件</span></a>）。</p>\n</section>\n<section id=\"installed-apps\">\n<span id=\"std-setting-INSTALLED_APPS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code><a class=\"heading-anchor\" href=\"#installed-apps\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>一个字符串的列表，表示在这个 Django 安装中所有被启用的应用程序。每一个字符串都应该是一个 Python 的点分隔路径。</p>\n<ul class=\"simple\">\n<li><p>应用程序配置类（首选），或</p></li>\n<li><p>包含应用程序的包。</p></li>\n</ul>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/applications/\"><span class=\"doc\">了解更多关于应用配置</span></a>。</p>\n<aside class=\"admonition-use-the-application-registry-for-introspection admonition\">\n<p class=\"admonition-title\">使用应用程序注册进行自省</p>\n<p>你的代码不应该直接访问 <a class=\"reference internal\" href=\"#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a>。使用 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/applications/#django.apps.apps\" title=\"django.apps.apps\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">django.apps.apps</span></code></a> 代替。</p>\n</aside>\n<aside class=\"admonition-application-names-and-labels-must-be-unique-in-setting-installed-apps admonition\">\n<p class=\"admonition-title\">在 <code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTLED_APPS</span></code> 中，应用程序名称和标签必须是唯一的。</p>\n<p>应用程序 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/applications/#django.apps.AppConfig.name\" title=\"django.apps.AppConfig.name\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">名称</span></code></a> ——指向应用程序包的点分隔 Python 路径——必须是唯一的。没有办法将同一个应用程序包含两次，除非用另一个名字复制它的代码。</p>\n<p>应用程序 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/applications/#django.apps.AppConfig.label\" title=\"django.apps.AppConfig.label\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">标签</span></code></a> ——默认情况下，名称的最后一部分也必须是唯一的。例如，你不能同时包含 <code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.auth</span></code> 和 <code class=\"docutils literal notranslate\"><span class=\"pre\">myproject.auth</span></code>。但是，你可以用自定义配置重新标注一个应用程序，定义不同的 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/applications/#django.apps.AppConfig.label\" title=\"django.apps.AppConfig.label\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">label</span></code></a>。</p>\n<p>无论 <a class=\"reference internal\" href=\"#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> 引用的是应用程序配置类还是应用包，这些规则都适用。</p>\n</aside>\n<p>当多个应用程序提供同一资源的不同版本（模板、静态文件、管理命令、翻译）时， <a class=\"reference internal\" href=\"#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> 中排在第一位的应用程序具有优先权。</p>\n</section>\n<section id=\"internal-ips\">\n<span id=\"std-setting-INTERNAL_IPS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">INTERNAL_IPS</span></code><a class=\"heading-anchor\" href=\"#internal-ips\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>一个 IP 地址的列表，作为字符串，它：</p>\n<ul class=\"simple\">\n<li><p>允许 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/api/#django.template.context_processors.debug\" title=\"django.template.context_processors.debug\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">debug()</span></code></a> 上下文处理器为模板上下文添加一些变量。</p></li>\n<li><p>即使不以员工用户身份登录，也可以使用 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/admin/admindocs/#admindocs-bookmarklets\"><span class=\"std std-ref\">管理文档书签</span></a>。</p></li>\n<li><p>在 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AdminEmailHandler</span></code></a> 邮件中被标记为“internal”（与 “EXTERNAL”相对）。</p></li>\n</ul>\n</section>\n<section id=\"language-code\">\n<span id=\"std-setting-LANGUAGE_CODE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGE_CODE</span></code><a class=\"heading-anchor\" href=\"#language-code\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'en-us'</span></code></p>\n<p>代表本次安装的语言代码的字符串。这应该是标准的 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/#term-language-code\"><span class=\"xref std std-term\">language ID 格式</span></a>。例如，美国英语是 <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;en-us&quot;</span></code>。也请参见 <a class=\"reference external\" href=\"http://www.i18nguy.com/unicode/language-identifiers.html\">语言标识符列表</a> 和 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/\"><span class=\"doc\">国际化和本地化</span></a>。</p>\n<p>它有三个目的：</p>\n<ul class=\"simple\">\n<li><p>如果没有使用 locale 中间件，它决定向所有用户提供哪种翻译。</p></li>\n<li><p>如果 locale 中间件是激活的，它提供了一个后备语言，以防用户的首选语言无法确定或网站不支持。当用户的首选语言不存在给定字词的翻译时，它也会提供后备翻译。</p></li>\n<li><p>如果通过 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/formatting/#std-templatefilter-unlocalize\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">unlocalize</span></code></a> 过滤器或 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/formatting/#std-templatetag-localize\"><code class=\"xref std std-ttag docutils literal notranslate\"><span class=\"pre\">{%</span> <span class=\"pre\">localize</span> <span class=\"pre\">off</span> <span class=\"pre\">%}</span></code></a> 标签显式禁用本地化，它将提供后备本地化格式，这些格式将替代应用。有关详细信息，请参阅 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/formatting/#topic-l10n-templates\"><span class=\"std std-ref\">在模板中控制本地化</span></a>。</p></li>\n</ul>\n<p>更多细节请参考 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/translation/#how-django-discovers-language-preference\"><span class=\"std std-ref\">Django 如何发现语言偏好</span></a>。</p>\n</section>\n<section id=\"language-cookie-age\">\n<span id=\"std-setting-LANGUAGE_COOKIE_AGE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_AGE</span></code><a class=\"heading-anchor\" href=\"#language-cookie-age\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> （浏览器关闭时失效）</p>\n<p>语言 cookie 的寿命，以秒为单位</p>\n</section>\n<section id=\"language-cookie-domain\">\n<span id=\"std-setting-LANGUAGE_COOKIE_DOMAIN\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_DOMAIN</span></code><a class=\"heading-anchor\" href=\"#language-cookie-domain\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>语言 cookie 使用的域。将其设置为一个字符串，如 <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;example.com&quot;</span></code> 用于跨域 cookie，或使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> 用于标准域 cookie。</p>\n<p>在生产型网站上更新此配置时要谨慎。如果你更新此配置，在以前使用标准域 cookie 的网站上启用跨域 cookie，则现有的具有旧域的用户 cookie 将不会被更新。这将导致网站用户无法切换语言，只要这些 cookie 持续存在。执行切换的唯一安全可靠的方案是永久更改语言 cookie 名称（通过 <a class=\"reference internal\" href=\"#std-setting-LANGUAGE_COOKIE_NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_NAME</span></code></a> 设置），并添加一个中间件，将旧 cookie 的值复制到新 cookie 中，然后删除旧 cookie。</p>\n</section>\n<section id=\"language-cookie-httponly\">\n<span id=\"std-setting-LANGUAGE_COOKIE_HTTPONLY\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_HTTPONLY</span></code><a class=\"heading-anchor\" href=\"#language-cookie-httponly\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否对语言 cookie 使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpOnly</span></code> 标志。如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，客户端的 JavaScript 将无法访问语言 cookie。</p>\n<p>关于 <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpOnly</span></code> 的详细信息，请参见 <a class=\"reference internal\" href=\"#std-setting-SESSION_COOKIE_HTTPONLY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_HTTPONLY</span></code></a>。</p>\n</section>\n<section id=\"language-cookie-name\">\n<span id=\"std-setting-LANGUAGE_COOKIE_NAME\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_NAME</span></code><a class=\"heading-anchor\" href=\"#language-cookie-name\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'django_language'</span></code></p>\n<p>用于语言 cookie 的 cookie 名称。这可以是任何你想要的（只要它与你的应用程序中的其他 cookie 名称不同）。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/\"><span class=\"doc\">国际化和本地化</span></a>。</p>\n</section>\n<section id=\"language-cookie-path\">\n<span id=\"std-setting-LANGUAGE_COOKIE_PATH\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_PATH</span></code><a class=\"heading-anchor\" href=\"#language-cookie-path\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'/'</span></code></p>\n<p>语言 cookie 上设置的路径。这个路径应该与你的 Django 安装的 URL 路径相匹配，或者是该路径的父路径。</p>\n<p>如果你有多个 Django 实例在同一个主机名下运行，这个功能很有用。他们可以使用不同的 cookie 路径，每个实例只能看到自己的语言 cookie。</p>\n<p>在生产型网站上更新此配置时要谨慎。如果你更新此配置，使用比以前更深的路径，则现有的用户 cookie 的旧路径将不会被更新。这将导致网站用户无法切换语言，只要这些 cookie 持续存在。执行切换的唯一安全可靠的方案是永久更改语言 cookie 的名称（通过 <a class=\"reference internal\" href=\"#std-setting-LANGUAGE_COOKIE_NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_NAME</span></code></a> 配置），并添加一个中间件，将旧 cookie 的值复制到新的 cookie 中，然后删除这个 cookie。</p>\n</section>\n<section id=\"language-cookie-samesite\">\n<span id=\"std-setting-LANGUAGE_COOKIE_SAMESITE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_SAMESITE</span></code><a class=\"heading-anchor\" href=\"#language-cookie-samesite\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>语言 cookie 上 <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value\">SameSite</a> 标志的值。该标志可防止在跨站点请求中发送 cookie。</p>\n<p>关于 <code class=\"docutils literal notranslate\"><span class=\"pre\">SameSite</span></code> 的详细信息，请参见 <a class=\"reference internal\" href=\"#std-setting-SESSION_COOKIE_SAMESITE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_SAMESITE</span></code></a>。</p>\n</section>\n<section id=\"language-cookie-secure\">\n<span id=\"std-setting-LANGUAGE_COOKIE_SECURE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_SECURE</span></code><a class=\"heading-anchor\" href=\"#language-cookie-secure\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否对语言 cookie 使用安全 cookie。如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，cookie 将被标记为“安全”，这意味着浏览器可以确保 cookie 只在 HTTPS 连接下发送。</p>\n</section>\n<section id=\"languages\">\n<span id=\"std-setting-LANGUAGES\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGES</span></code><a class=\"heading-anchor\" href=\"#languages\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认值。所有可用语言的清单。这个列表在不断的增加，如果在这里加入一个副本，那么不可避免的会很快过时。你可以在 <a class=\"extlink-source reference external\" href=\"https://github.com/django/django/blob/stable/6.1.x/django/conf/global_settings.py\">django/conf/global_settings.py</a> 中查看当前的翻译语言列表。</p>\n<p>该列表是由格式为 (<a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/#term-language-code\"><span class=\"xref std std-term\">语言代码</span></a>, <code class=\"docutils literal notranslate\"><span class=\"pre\">语言名称</span></code>) 的 2 元组组成，例如，<code class=\"docutils literal notranslate\"><span class=\"pre\">('ja',</span> <span class=\"pre\">'Japanese')</span></code>。这指定了哪些语言可用于语言选择。请参阅 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/\"><span class=\"doc\">国际化和本地化</span></a>。</p>\n<p>一般来说，默认值就可以了。只有当你想将语言选择限制在 Django 提供的语言子集时，才需要设置此配置。</p>\n<p>如果你定义了一个自定义的 <a class=\"reference internal\" href=\"#std-setting-LANGUAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGES</span></code></a> 配置，你可以使用 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/utils/#django.utils.translation.gettext_lazy\" title=\"django.utils.translation.gettext_lazy\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">gettext_lazy()</span></code></a> 函数将语言名称标记为翻译字符串。</p>\n<p>以下是一个示例配置文件：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.utils.translation</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">gettext_lazy</span> <span class=\"k\">as</span> <span class=\"n\">_</span>\n\n<span class=\"n\">LANGUAGES</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;de&quot;</span><span class=\"p\">,</span> <span class=\"n\">_</span><span class=\"p\">(</span><span class=\"s2\">&quot;German&quot;</span><span class=\"p\">)),</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;en&quot;</span><span class=\"p\">,</span> <span class=\"n\">_</span><span class=\"p\">(</span><span class=\"s2\">&quot;English&quot;</span><span class=\"p\">)),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n</section>\n<section id=\"languages-bidi\">\n<span id=\"std-setting-LANGUAGES_BIDI\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LANGUAGES_BIDI</span></code><a class=\"heading-anchor\" href=\"#languages-bidi\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认值。所有从右到左书写的语言代码的列表。你可以在 <a class=\"extlink-source reference external\" href=\"https://github.com/django/django/blob/stable/6.1.x/django/conf/global_settings.py\">django/conf/global_settings.py</a> 中查看这些语言的当前列表。</p>\n<p>列表中包含 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/#term-language-code\"><span class=\"xref std std-term\">语言代码</span></a>，用于从右到左书写的语言。</p>\n<p>一般来说，默认值就可以了。只有当你想将语言选择限制在 Django 提供的语言子集时，才设置这个配置。如果你定义了一个自定义的 <a class=\"reference internal\" href=\"#std-setting-LANGUAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGES</span></code></a> 配置，双向语言列表中可能会包含一些在特定网站上没有启用的语言代码。</p>\n</section>\n<section id=\"locale-paths\">\n<span id=\"std-setting-LOCALE_PATHS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LOCALE_PATHS</span></code><a class=\"heading-anchor\" href=\"#locale-paths\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>Django 寻找翻译文件的目录列表。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/i18n/translation/#how-django-discovers-translations\"><span class=\"std std-ref\">Django 如何发现翻译</span></a>。</p>\n<p>举例：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">LOCALE_PATHS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;/home/www/project/common_files/locale&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;/var/local/translations/locale&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>Django 会在这些路径中寻找包含实际翻译文件的 <code class=\"docutils literal notranslate\"><span class=\"pre\">&lt;locale_code&gt;/LC_MESSAGES</span></code> 目录。</p>\n</section>\n<section id=\"logging\">\n<span id=\"std-setting-LOGGING\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LOGGING</span></code><a class=\"heading-anchor\" href=\"#logging\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：日志配置字典。</p>\n<p>一个包含配置信息的数据结构。当不为空时，这个数据结构的内容将作为参数传递给 <a class=\"reference internal\" href=\"#std-setting-LOGGING_CONFIG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING_CONFIG</span></code></a> 中描述的配置方法。</p>\n<p>其中，当 <a class=\"reference internal\" href=\"#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> 为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> 时，默认的日志配置会将 HTTP 500 服务器错误传递给电子邮件日志处理程序。也请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/logging/#configuring-logging\"><span class=\"std std-ref\">日志模块的配置</span></a>。</p>\n<p>你可以通过查看 <a class=\"extlink-source reference external\" href=\"https://github.com/django/django/blob/stable/6.1.x/django/utils/log.py\">django/utils/log.py</a> 中的默认日志配置。</p>\n</section>\n<section id=\"logging-config\">\n<span id=\"std-setting-LOGGING_CONFIG\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LOGGING_CONFIG</span></code><a class=\"heading-anchor\" href=\"#logging-config\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'logging.config.dictConfig'</span></code></p>\n<p>Django 项目中用于配置日志的可调用路径。默认指向 Python 的 <a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.config.html#logging-config-dictschema\" title=\"(in Python v3.14)\"><span class=\"xref std std-ref\">dictConfig</span></a> 配置方法的实例。</p>\n<p>如果将 <a class=\"reference internal\" href=\"#std-setting-LOGGING_CONFIG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING_CONFIG</span></code></a> 配置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，将跳过日志配置过程。</p>\n</section>\n<section id=\"mailers\">\n<span id=\"std-setting-MAILERS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code><a class=\"heading-anchor\" href=\"#mailers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"version-note version-added\" data-version=\"6.1\">\n<p class=\"version-note-title\">New in Django 6.1</p></aside>\n<p>默认：未定义</p>\n<p>A dictionary containing the settings for all email backends to be used with\nDjango. It is a nested dictionary that maps backend aliases to dictionaries\ncontaining each mailer's backend import path and configuration options.</p>\n<p>举例：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">MAILERS</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;smtp.example.net&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;newsletters&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;smtp.bulk-email-service.example.com&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;username&quot;</span><span class=\"p\">:</span> <span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">environ</span><span class=\"p\">[</span><span class=\"s2\">&quot;BULK_EMAIL_SERVICE_ACCOUNT_ID&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;password&quot;</span><span class=\"p\">:</span> <span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">environ</span><span class=\"p\">[</span><span class=\"s2\">&quot;BULK_EMAIL_SERVICE_API_KEY&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;use_tls&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>If you plan to send email through Django, configuring at least a <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;default&quot;</span></code>\nmailer is recommended. Any number of additional mailers may also be specified.\nDepending on which backend is used, other options may be required.</p>\n<p>Setting <code class=\"docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code> to an empty dictionary (<code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code>) disables email sending and\nany attempt to send mail will raise <code class=\"docutils literal notranslate\"><span class=\"pre\">MailerDoesNotExist</span></code>.</p>\n<p>See <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#topic-email-configuration\"><span class=\"std std-ref\">Configuring email</span></a> for more information.</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>In Django 7.0, the default value will change from &quot;Not defined&quot; to <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code>.\nUntil then, if <code class=\"docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code> is not defined in the project's settings, Django\nwill create a <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;default&quot;</span></code> mailer using the <a class=\"reference internal\" href=\"#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_BACKEND</span></code></a>\nsetting. Projects can opt into the Django 7.0 behavior at any time by\nadding <code class=\"docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code> and removing <code class=\"docutils literal notranslate\"><span class=\"pre\">EMAIL_BACKEND</span></code> from their settings. See\n<a class=\"reference internal\" href=\"/zh-hans/6.1/howto/mailers-migration/#migrating-to-mailers-settings\"><span class=\"std std-ref\">Migrating settings</span></a>.</p>\n</aside>\n<section id=\"std-setting-MAILERS-BACKEND\">\n<span id=\"id6\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code><a class=\"heading-anchor\" href=\"#std-setting-MAILERS-BACKEND\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Default: <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span></code></p>\n<p>The Python import path to the email backend class. If <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;BACKEND&quot;</span></code> is omitted,\nDjango's <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#topic-email-smtp-backend\"><span class=\"std std-ref\">SMTP 后端</span></a> is used.</p>\n<p>See <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#topic-email-backends\"><span class=\"std std-ref\">邮件后端</span></a> for a list of Django's built-in backends and\npointers to community-maintained options.</p>\n</section>\n<section id=\"std-setting-MAILERS-OPTIONS\">\n<span id=\"id7\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code><a class=\"heading-anchor\" href=\"#std-setting-MAILERS-OPTIONS\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Default: <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code></p>\n<p>Configuration parameters to pass to the email backend. The available and\nrequired options vary depending on the backend.</p>\n</section>\n</section>\n<section id=\"managers\">\n<span id=\"std-setting-MANAGERS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code><a class=\"heading-anchor\" href=\"#managers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>一个与 <a class=\"reference internal\" href=\"#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a> 格式相同的列表，用于指定当 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">BrokenLinkEmailsMiddleware</span></code></a> 被启用时，谁应该收到断链通知。</p>\n<aside class=\"version-note version-changed\" data-version=\"6.0\">\n<p class=\"version-note-title\">Changed in Django 6.0</p><p>In older versions, required a list of (name, address) tuples.</p>\n</aside>\n</section>\n<section id=\"media-root\">\n<span id=\"std-setting-MEDIA_ROOT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code><a class=\"heading-anchor\" href=\"#media-root\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>保存 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/files/\"><span class=\"doc\">用户上传的文件</span></a> 目录的绝对文件系统路径。</p>\n<p>例如： <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;/var/www/example.com/media/&quot;</span></code></p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_URL</span></code></a>。</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p><a class=\"reference internal\" href=\"#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> 必须有不同的值。在引入 <a class=\"reference internal\" href=\"#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> 之前，通常依靠或回溯 <a class=\"reference internal\" href=\"#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code></a> 来提供静态文件；然而，由于这可能会产生严重的安全影响，因此有一个验证检查来防止这种情况。</p>\n</aside>\n</section>\n<section id=\"media-url\">\n<span id=\"std-setting-MEDIA_URL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MEDIA_URL</span></code><a class=\"heading-anchor\" href=\"#media-url\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>处理从 <a class=\"reference internal\" href=\"#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code></a> 提供的媒体的 URL，用于 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/files/\"><span class=\"doc\">管理存储文件</span></a>。如果设置为非空值，则必须以斜线结束。在开发和生产环境中，你都需要 <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/static-files/#serving-uploaded-files-in-development\"><span class=\"std std-ref\">配置这些文件被服务</span></a>。</p>\n<p>如果你想在模板中使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">{{</span> <span class=\"pre\">MEDIA_URL</span> <span class=\"pre\">}}</span></code>，在 <a class=\"reference internal\" href=\"#std-setting-TEMPLATES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TEMPLATES</span></code></a> 的 <code class=\"docutils literal notranslate\"><span class=\"pre\">''context_processors'</span></code> 选项中添加 <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.template.context_processors.media'</span></code>。</p>\n<p>示例：<code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;https://media.example.com/&quot;</span></code></p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>如果接收不受信任的用户的上传会有安全隐患， 请阅读 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/security/#user-uploaded-content-security\"><span class=\"std std-ref\">用户上传内容</span></a> 获取详情.</p>\n</aside>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p><a class=\"reference internal\" href=\"#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_URL</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-STATIC_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_URL</span></code></a> 必须有不同的值。更多细节请参见 <a class=\"reference internal\" href=\"#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code></a>。</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>如果 <a class=\"reference internal\" href=\"#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_URL</span></code></a> 是一个相对路径，那么它将以服务器提供的 <code class=\"docutils literal notranslate\"><span class=\"pre\">SCRIPT_NAME</span></code> 的值为前缀（如果没有设置，则为 <code class=\"docutils literal notranslate\"><span class=\"pre\">/</span></code>）。这使得在子路径中服务 Django 应用时更容易，而无需额外增加配置。</p>\n</aside>\n</section>\n<section id=\"middleware\">\n<span id=\"std-setting-MIDDLEWARE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code><a class=\"heading-anchor\" href=\"#middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>要使用的中间件列表。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/middleware/\"><span class=\"doc\">中间件</span></a>。</p>\n</section>\n<section id=\"migration-modules\">\n<span id=\"std-setting-MIGRATION_MODULES\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MIGRATION_MODULES</span></code><a class=\"heading-anchor\" href=\"#migration-modules\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code> （空字典）</p>\n<p>一个指定包的字典，在每个应用程序的基础上可以找到迁移模块。这个配置的默认值是一个空字典，但迁移模块的默认包名是 <code class=\"docutils literal notranslate\"><span class=\"pre\">migrations</span></code>。</p>\n<p>举例：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">{</span><span class=\"s2\">&quot;blog&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;blog.db_migrations&quot;</span><span class=\"p\">}</span>\n</code></pre></div>\n<p>在这种情况下，与 <code class=\"docutils literal notranslate\"><span class=\"pre\">blog</span></code> 应用有关的迁移将包含在 <code class=\"docutils literal notranslate\"><span class=\"pre\">blog.db_migrations</span></code> 包中。</p>\n<p>如果你提供了 <code class=\"docutils literal notranslate\"><span class=\"pre\">app_label</span></code> 参数， <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#django-admin-makemigrations\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">makemigrations</span></code></a> 将自动创建包，如果它还不存在。</p>\n<p>当你为一个应用程序提供 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> 作为一个值时，Django 会将该应用程序视为一个没有迁移的应用程序，而不考虑是否存在 <code class=\"docutils literal notranslate\"><span class=\"pre\">migrations</span></code> 子模块。例如，在测试设置文件中，这可以用来在测试时跳过迁移（仍然会为应用程序的模型创建表）。要在测试期间禁止所有应用程序的迁移，你可以将 <a class=\"reference internal\" href=\"#std-setting-TEST_MIGRATE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIGRATE</span></code></a> 设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>。如果在你的一般项目配置中使用了 <code class=\"docutils literal notranslate\"><span class=\"pre\">MIGRATION_MODULES</span></code>，如果你想为应用程序创建表，记得使用 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#cmdoption-migrate-run-syncdb\"><code class=\"xref std std-option docutils literal notranslate\"><span class=\"pre\">migrate</span> <span class=\"pre\">--run-syncdb</span></code></a> 选项。</p>\n</section>\n<section id=\"month-day-format\">\n<span id=\"std-setting-MONTH_DAY_FORMAT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MONTH_DAY_FORMAT</span></code><a class=\"heading-anchor\" href=\"#month-day-format\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'F</span> <span class=\"pre\">j'</span></code></p>\n<p>在 Django admin change-list 页面上的日期字段的默认格式——也可能被系统的其他部分使用——在只显示月份和日期的情况下。</p>\n<p>例如，当 Django 管理员的变更列表页面被日期 drilldown 过滤时，给定的一天的标题会显示日期和月份。不同的地域有不同的格式。例如，美国英语会说“January 1”，而西班牙语可能会说“1 Enero”。</p>\n<p>请注意，相应的由区域设置规定的格式具有更高的优先级，将会被应用。</p>\n<p>查看 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">允许的日期格式字符串</span></code></a>。另见 <a class=\"reference internal\" href=\"#std-setting-DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_FORMAT</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_FORMAT</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-TIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_FORMAT</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-YEAR_MONTH_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">YEAR_MONTH_FORMAT</span></code></a>。</p>\n</section>\n<section id=\"number-grouping\">\n<span id=\"std-setting-NUMBER_GROUPING\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">NUMBER_GROUPING</span></code><a class=\"heading-anchor\" href=\"#number-grouping\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code></p>\n<p>一个数字的整数部分的数字组合在一起的数量。</p>\n<p>常见的用途是显示千位数的分隔符。如果该设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code>，则不会对该数字进行分组。如果这个设置大于 <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code>，那么 <a class=\"reference internal\" href=\"#std-setting-THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">THOUSAND_SEPARATOR</span></code></a> 将被用作这些组之间的分隔符。</p>\n<p>有些地方使用非统一的数字分组，例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">en_IN</span></code> 中的 <code class=\"docutils literal notranslate\"><span class=\"pre\">10,00,00,000</span></code>。对于这种情况，你可以提供一个序列，其中包含要应用的数字组大小。第一个数字定义小数定界符之前的组的大小，后面的每个数字定义前面组的大小。如果序列以 <code class=\"docutils literal notranslate\"><span class=\"pre\">-1</span></code> 结束，则不会再进行分组。如果序列以 <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code> 结束，则在剩余的数字中使用最后一组的大小。</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">en_IN</span></code> 的元组示例：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">NUMBER_GROUPING</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"mi\">3</span><span class=\"p\">,</span> <span class=\"mi\">2</span><span class=\"p\">,</span> <span class=\"mi\">0</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>请注意，由区域设置规定的格式具有更高的优先级，将会被应用。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DECIMAL_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DECIMAL_SEPARATOR</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">THOUSAND_SEPARATOR</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-USE_THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_THOUSAND_SEPARATOR</span></code></a>。</p>\n</section>\n<section id=\"prepend-www\">\n<span id=\"std-setting-PREPEND_WWW\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">PREPEND_WWW</span></code><a class=\"heading-anchor\" href=\"#prepend-www\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否给没有“www.”子域的 URL 加前缀。只有在安装了 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.common.CommonMiddleware\" title=\"django.middleware.common.CommonMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CommonMiddleware</span></code></a> 的情况下才会使用（参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/middleware/\"><span class=\"doc\">中间件</span></a>）。也请参见 <a class=\"reference internal\" href=\"#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a>。</p>\n</section>\n<section id=\"root-urlconf\">\n<span id=\"std-setting-ROOT_URLCONF\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">ROOT_URLCONF</span></code><a class=\"heading-anchor\" href=\"#root-urlconf\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：未定义</p>\n<p>一个字符串，代表你的根 URLconf 的完整 Python 导入路径，例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;mydjangoapps.urls&quot;</span></code>。可以通过在传入的 <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code> 对象上设置属性 <code class=\"docutils literal notranslate\"><span class=\"pre\">urlconf</span></code> 来覆盖每个请求。详情请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/urls/#how-django-processes-a-request\"><span class=\"std std-ref\">Django 如何处理一个请求</span></a>。</p>\n</section>\n<section id=\"secret-key\">\n<span id=\"std-setting-SECRET_KEY\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code><a class=\"heading-anchor\" href=\"#secret-key\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>一个特定 Django 安装的密钥。用于提供 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/signing/\"><span class=\"doc\">加密签名</span></a>，并且应该设置为一个唯一的、不可预测的值。</p>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">django-admin</span> <span class=\"pre\">startproject</span></code></a> 自动为每个新项目添加一个随机生成的 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code>。</p>\n<p>键的使用不应该假设是文本或字节。每次使用都应该通过 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/utils/#django.utils.encoding.force_str\" title=\"django.utils.encoding.force_str\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">force_str()</span></code></a> 或 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/utils/#django.utils.encoding.force_bytes\" title=\"django.utils.encoding.force_bytes\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">force_bytes()</span></code></a> 将其转换为所需类型。</p>\n<p>如果 <a class=\"reference internal\" href=\"#std-setting-SECRET_KEY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code></a> 没有设置，Django 将拒绝启动。</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p><strong>将此值保密。</strong></p>\n<p>在已知的 <a class=\"reference internal\" href=\"#std-setting-SECRET_KEY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code></a> 的情况下运行 Django，会破坏 Django 的许多安全保护措施，并可能导致权限升级和远程代码执行漏洞。</p>\n</aside>\n<p>密钥用于：</p>\n<ul class=\"simple\">\n<li><p>All <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/sessions/\"><span class=\"doc\">sessions</span></a> if you are using\nany other session backend than <code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.sessions.backends.cache</span></code>,\nor are using the default\n<a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/customizing/#django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash\" title=\"django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_session_auth_hash()</span></code></a>.</p></li>\n<li><p>所有 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/\"><span class=\"doc\">消息</span></a>，如果你使用了 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#django.contrib.messages.storage.cookie.CookieStorage\" title=\"django.contrib.messages.storage.cookie.CookieStorage\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CookieStorage</span></code></a> 或 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#django.contrib.messages.storage.fallback.FallbackStorage\" title=\"django.contrib.messages.storage.fallback.FallbackStorage\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FallbackStorage</span></code></a>。</p></li>\n<li><p>所有 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/default/#django.contrib.auth.views.PasswordResetView\" title=\"django.contrib.auth.views.PasswordResetView\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">PasswordResetView</span></code></a> 密钥。</p></li>\n<li><p><a class=\"reference internal\" href=\"/zh-hans/6.1/topics/signing/\"><span class=\"doc\">加密签名</span></a> 的任何使用，除非提供不同的密钥。</p></li>\n</ul>\n<p>当一个密钥不再设置为 <a class=\"reference internal\" href=\"#std-setting-SECRET_KEY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code></a> 或包含在 <a class=\"reference internal\" href=\"#std-setting-SECRET_KEY_FALLBACKS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY_FALLBACKS</span></code></a> 中时，上述所有内容都将无效。在旋转密钥时，你应该将旧密钥临时移动到 <a class=\"reference internal\" href=\"#std-setting-SECRET_KEY_FALLBACKS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY_FALLBACKS</span></code></a>。密钥旋转不会影响用户的密码，密钥旋转不会影响用户的密码。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>默认的 <code class=\"file docutils literal notranslate\"><span class=\"pre\">settings.py</span></code> 文件由 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">django-admin</span> <span class=\"pre\">startproject</span></code></a> 创建，为方便起见，创建了一个唯一的 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code>。</p>\n</aside>\n</section>\n<section id=\"secret-key-fallbacks\">\n<span id=\"std-setting-SECRET_KEY_FALLBACKS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY_FALLBACKS</span></code><a class=\"heading-anchor\" href=\"#secret-key-fallbacks\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code></p>\n<p>一个特定 Django 安装的回退密钥列表。这些密钥用于允许旋转 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code>。</p>\n<p>为了旋转你的密钥，设置一个新的 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code> 并将之前的值移动到 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY_FALLBACKS</span></code> 的开头。然后在准备过期使用它们的会话、密码重置令牌等时，从 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY_FALLBACKS</span></code> 的末尾删除旧值。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>签名操作计算成本较高。在 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY_FALLBACKS</span></code> 中有多个旧密钥值会为所有与之前的密钥不匹配的检查增加额外的开销。</p>\n<p>因此，在适当的时期后，应删除回退值，以允许密钥旋转。</p>\n</aside>\n<p>密钥值的用途不应假定它们是文本或字节。每次使用应通过 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/utils/#django.utils.encoding.force_str\" title=\"django.utils.encoding.force_str\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">force_str()</span></code></a> 或 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/utils/#django.utils.encoding.force_bytes\" title=\"django.utils.encoding.force_bytes\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">force_bytes()</span></code></a> 进行转换为所需的类型。</p>\n</section>\n<section id=\"secure-content-type-nosniff\">\n<span id=\"std-setting-SECURE_CONTENT_TYPE_NOSNIFF\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_CONTENT_TYPE_NOSNIFF</span></code><a class=\"heading-anchor\" href=\"#secure-content-type-nosniff\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code></p>\n<p>如果 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，则 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a> 会在所有响应中设置 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#x-content-type-options\"><span class=\"std std-ref\">X-Content-Type-Options: nosniff</span></a> 头。</p>\n</section>\n<section id=\"secure-cross-origin-opener-policy\">\n<span id=\"std-setting-SECURE_CROSS_ORIGIN_OPENER_POLICY\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_CROSS_ORIGIN_OPENER_POLICY</span></code><a class=\"heading-anchor\" href=\"#secure-cross-origin-opener-policy\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'same-origin'</span></code></p>\n<p>除非设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，否则 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a> 会在所有没有此头的响应上设置 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#cross-origin-opener-policy\"><span class=\"std std-ref\">跨域开启策略</span></a> 头部为提供的值。</p>\n</section>\n<section id=\"secure-csp\">\n<span id=\"std-setting-SECURE_CSP\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_CSP</span></code><a class=\"heading-anchor\" href=\"#secure-csp\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"version-note version-added\" data-version=\"6.0\">\n<p class=\"version-note-title\">New in Django 6.0</p></aside>\n<p>Default: <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code></p>\n<p>This setting defines the directives used by the\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.csp.ContentSecurityPolicyMiddleware\" title=\"django.middleware.csp.ContentSecurityPolicyMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ContentSecurityPolicyMiddleware</span></code></a>, which\ngenerates and adds a <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/csp/#csp-overview\"><span class=\"std std-ref\">Content-Security-Policy</span></a> (CSP) header\nto all responses that do not already include one.</p>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Security-Policy</span></code> header instructs browsers to restrict which\nresources a page is allowed to load. A properly configured CSP can block\ncontent that violates defined rules, helping prevent cross-site scripting (XSS)\nand other content injection attacks by explicitly declaring trusted sources for\ncontent such as scripts, styles, images, fonts, and more.</p>\n<p>The setting must be a mapping (typically a dictionary) of directive names to\ntheir values. Each key should be a valid CSP directive such as <code class=\"docutils literal notranslate\"><span class=\"pre\">default-src</span></code>\nor <code class=\"docutils literal notranslate\"><span class=\"pre\">script-src</span></code>. The corresponding value can be a list, tuple, or set of\nsource expressions or URLs to allow for that directive. If a set is used, it\nwill be automatically sorted to ensure consistent output in the generated\nheaders.</p>\n<p>This example illustrates the expected structure, using the constants defined in\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/csp/#csp-constants\"><span class=\"std std-ref\">CSP constants</span></a>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.utils.csp</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">CSP</span>\n\n<span class=\"n\">SECURE_CSP</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default-src&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"n\">CSP</span><span class=\"o\">.</span><span class=\"n\">SELF</span><span class=\"p\">],</span>\n    <span class=\"s2\">&quot;img-src&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;data:&quot;</span><span class=\"p\">,</span> <span class=\"n\">CSP</span><span class=\"o\">.</span><span class=\"n\">SELF</span><span class=\"p\">,</span> <span class=\"s2\">&quot;https://images.example.com&quot;</span><span class=\"p\">],</span>\n    <span class=\"s2\">&quot;frame-src&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"n\">CSP</span><span class=\"o\">.</span><span class=\"n\">NONE</span><span class=\"p\">],</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<aside class=\"admonition-directives-validation admonition\">\n<p class=\"admonition-title\">Directives validation</p>\n<p>Django's CSP middleware helps construct and send the appropriate header\nbased on your settings, but it does <strong>not validate</strong> that the directives and\nvalues conform to the CSP specification. It is your responsibility to ensure\nthat the configuration is syntactically and semantically correct. Use\nbrowser developer tools or external CSP validators during development.</p>\n<p>For a list of available directives and their values, refer to the <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#directives\">MDN\ndocumentation on CSP directives</a>.</p>\n</aside>\n</section>\n<section id=\"secure-csp-report-only\">\n<span id=\"std-setting-SECURE_CSP_REPORT_ONLY\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_CSP_REPORT_ONLY</span></code><a class=\"heading-anchor\" href=\"#secure-csp-report-only\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"version-note version-added\" data-version=\"6.0\">\n<p class=\"version-note-title\">New in Django 6.0</p></aside>\n<p>Default: <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code></p>\n<p>This setting is just like <a class=\"reference internal\" href=\"#std-setting-SECURE_CSP\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CSP</span></code></a>, but instead of enforcing the\npolicy, it instructs the\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.csp.ContentSecurityPolicyMiddleware\" title=\"django.middleware.csp.ContentSecurityPolicyMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ContentSecurityPolicyMiddleware</span></code></a> to apply a\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Security-Policy-Report-Only</span></code> header to responses, which allows\nbrowsers to monitor and report policy violations without blocking content. This\nis useful for testing and refining a policy before enforcement.</p>\n<p>Most browsers log CSP violations to the developer console and can optionally\nsend them to a reporting endpoint. To collect these reports, the <code class=\"docutils literal notranslate\"><span class=\"pre\">report-uri</span></code>\ndirective must be defined (see <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/csp/#csp-reports\"><span class=\"std std-ref\">Policy violation reports</span></a> for more details).</p>\n<p>As noted in the <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only\">MDN documentation on Content-Security-Policy-Report-Only</a>,\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">report-uri</span></code> directive must be specified for reports to be sent;\notherwise, the header has no reporting effect (other than logging to the\nbrowser's developer tools console).</p>\n<p>Following the example from the <a class=\"reference internal\" href=\"#std-setting-SECURE_CSP\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CSP</span></code></a> setting:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.utils.csp</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">CSP</span>\n\n<span class=\"n\">SECURE_CSP_REPORT_ONLY</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default-src&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"n\">CSP</span><span class=\"o\">.</span><span class=\"n\">SELF</span><span class=\"p\">],</span>\n    <span class=\"s2\">&quot;img-src&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;data:&quot;</span><span class=\"p\">,</span> <span class=\"n\">CSP</span><span class=\"o\">.</span><span class=\"n\">SELF</span><span class=\"p\">,</span> <span class=\"s2\">&quot;https://images.example.com&quot;</span><span class=\"p\">],</span>\n    <span class=\"s2\">&quot;frame-src&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"n\">CSP</span><span class=\"o\">.</span><span class=\"n\">NONE</span><span class=\"p\">],</span>\n    <span class=\"s2\">&quot;report-uri&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;/my-site/csp/reports/&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n</section>\n<section id=\"secure-hsts-include-subdomains\">\n<span id=\"std-setting-SECURE_HSTS_INCLUDE_SUBDOMAINS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_INCLUDE_SUBDOMAINS</span></code><a class=\"heading-anchor\" href=\"#secure-hsts-include-subdomains\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>如果 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，则 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a> 在 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#http-strict-transport-security\"><span class=\"std std-ref\">HTTP 严格传输安全</span></a> 头中添加 <code class=\"docutils literal notranslate\"><span class=\"pre\">includeSubDomains</span></code> 指令。除非  <a class=\"reference internal\" href=\"#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span></code></a> 被设置为非零值，否则它没有任何效果。</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>如果设置不正确，可能会不可逆地（对于 <a class=\"reference internal\" href=\"#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span></code></a> 的值）破坏你的网站。请先阅读 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#http-strict-transport-security\"><span class=\"std std-ref\">HTTP 严格传输安全</span></a> 文档。</p>\n</aside>\n</section>\n<section id=\"secure-hsts-preload\">\n<span id=\"std-setting-SECURE_HSTS_PRELOAD\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_PRELOAD</span></code><a class=\"heading-anchor\" href=\"#secure-hsts-preload\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>如果 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，则 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a> 在 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#http-strict-transport-security\"><span class=\"std std-ref\">HTTP 严格传输安全</span></a> 头中添加 <code class=\"docutils literal notranslate\"><span class=\"pre\">preload</span></code> 指令。除非 <a class=\"reference internal\" href=\"#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span></code></a> 设置为非零值，否则没有效果。</p>\n</section>\n<section id=\"secure-hsts-seconds\">\n<span id=\"std-setting-SECURE_HSTS_SECONDS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span></code><a class=\"heading-anchor\" href=\"#secure-hsts-seconds\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code></p>\n<p>如果设置为非零的整数值，则 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a> 会对所有尚未设置 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#http-strict-transport-security\"><span class=\"std std-ref\">HTTP 严格传输安全</span></a> 头的响应进行设置。</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>不正确的设置可能会不可逆地（在一段时间内）破坏你的网站。请先阅读 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#http-strict-transport-security\"><span class=\"std std-ref\">HTTP 严格传输安全</span></a> 文档。</p>\n</aside>\n</section>\n<section id=\"secure-proxy-ssl-header\">\n<span id=\"std-setting-SECURE_PROXY_SSL_HEADER\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_PROXY_SSL_HEADER</span></code><a class=\"heading-anchor\" href=\"#secure-proxy-ssl-header\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>一个表示 HTTP 头部/值组合的元组，表示请求是安全的。这控制了请求对象的 <code class=\"docutils literal notranslate\"><span class=\"pre\">is_secure()</span></code> 方法的行为。</p>\n<p>默认情况下，<code class=\"docutils literal notranslate\"><span class=\"pre\">is_secure()</span></code> 通过确认请求的 URL 使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">https://</span></code> 来判断请求是否安全。这个方法对 Django 的 CSRF 保护很重要，你自己的代码或第三方应用可能会用到它。</p>\n<p>如果你的 Django 应用是在代理服务器后面，那么无论原始请求是否使用 HTTPS，代理服务器都可能会“吞噬”。如果代理和 Django 之间有一个非 HTTPS 的连接，那么 <code class=\"docutils literal notranslate\"><span class=\"pre\">is_secure()</span></code> 总是返回 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> ——即使是终端用户通过 HTTPS 发出的请求。相反，如果代理和 Django 之间有 HTTPS 连接，那么 <code class=\"docutils literal notranslate\"><span class=\"pre\">is_secure()</span></code> 将总是返回 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> ——即使是对最终用户通过 HTTPS 发出的请求。</p>\n<p>在这种情况下，配置你的代理服务器，设置一个自定义的 HTTP 头，告诉 Django 这个请求是否是通过 HTTPS 进来的，并设置 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_PROXY_SSL_HEADER</span></code>，这样 Django 就知道要找什么头了。</p>\n<p>设置一个包含两个元素的元组——要查找的头的名称和所需的值。例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">SECURE_PROXY_SSL_HEADER</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"s2\">&quot;HTTP_X_FORWARDED_PROTO&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;https&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>这告诉 Django 信任来自代理的 <code class=\"docutils literal notranslate\"><span class=\"pre\">X-Forwarded-Proto</span></code> 头部，并且在以下情况下请求是安全的（即，它最初通过 HTTPS 进入）：</p>\n<ul class=\"simple\">\n<li><p>头部值为 <code class=\"docutils literal notranslate\"><span class=\"pre\">'https'</span></code>，或者</p></li>\n<li><p>在协议的逗号分隔列表中，其初始、最左边的值为 <code class=\"docutils literal notranslate\"><span class=\"pre\">'https'</span></code> （例如，<code class=\"docutils literal notranslate\"><span class=\"pre\">'https,http,http'</span></code>）。</p></li>\n</ul>\n<p>如果你控制了你的代理或者有其他的保证，你应该 <em>只</em> 设置这个配置，它可以适当地设置／剥离这个头。</p>\n<p>需要注意的是，头的格式需要和 <code class=\"docutils literal notranslate\"><span class=\"pre\">request.META</span></code> 使用的格式一样——全大写，并且可能以 <code class=\"docutils literal notranslate\"><span class=\"pre\">HTTP_</span></code> 开头。（记住，Django 会在 x-header 名称的开头自动加上 <code class=\"docutils literal notranslate\"><span class=\"pre\">'HTTP_'</span></code>，然后才会在 <code class=\"docutils literal notranslate\"><span class=\"pre\">request.META</span></code> 中使用。）</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p><strong>修改此设置可能会危及你网站的安全。在更改之前，请确保你完全了解你的配置。</strong></p>\n<p>在设置之前，请确保以下所有内容为真（假设上面例子中的数值）。</p>\n<ul class=\"simple\">\n<li><p>你的 Django 应用在代理服务器后面。</p></li>\n<li><p>你的代理会从所有传入的请求中剥离 <code class=\"docutils literal notranslate\"><span class=\"pre\">X-Forwarded-Proto</span></code> 头部，即使它包含逗号分隔的协议列表。换句话说，如果最终用户在他们的请求中包含该头部，代理会将其丢弃。</p></li>\n<li><p>你的代理设置了 <code class=\"docutils literal notranslate\"><span class=\"pre\">X-Forwarded-Proto</span></code> 头，并将其发送给 Django，但只针对最初通过 HTTPS 进来的请求。</p></li>\n</ul>\n<p>如果其中任何一个不是真的，你应该将这个配置设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，并找到另一种确定 HTTPS 的方法，也许是通过自定义中间件。</p>\n</aside>\n</section>\n<section id=\"secure-redirect-exempt\">\n<span id=\"std-setting-SECURE_REDIRECT_EXEMPT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_REDIRECT_EXEMPT</span></code><a class=\"heading-anchor\" href=\"#secure-redirect-exempt\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>如果一个 URL 路径与这个列表中的正则表达式相匹配，那么请求将不会被重定向到 HTTPS。<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a> 会从 URL 路径中去掉前导斜杠，所以模式不应该包含它们，例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_REDIRECT_EXEMPT</span> <span class=\"pre\">=</span> <span class=\"pre\">[r'^no-ssl/$',</span> <span class=\"pre\">...]</span></code>。如果 <a class=\"reference internal\" href=\"#std-setting-SECURE_SSL_REDIRECT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code></a> 是 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>，这个配置就没有效果。</p>\n</section>\n<section id=\"secure-referrer-policy\">\n<span id=\"std-setting-SECURE_REFERRER_POLICY\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_REFERRER_POLICY</span></code><a class=\"heading-anchor\" href=\"#secure-referrer-policy\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'same-origin'</span></code></p>\n<p>如果设置了 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a>，则会在所有响应中设置 :ref:<a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>referrer-policy`头，如果还没有该头，则将其设置为提供的值。</p>\n</section>\n<section id=\"secure-ssl-host\">\n<span id=\"std-setting-SECURE_SSL_HOST\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_HOST</span></code><a class=\"heading-anchor\" href=\"#secure-ssl-host\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>如果是一个字符串（如 <code class=\"docutils literal notranslate\"><span class=\"pre\">secure.example.com</span></code>），所有 SSL 重定向都将指向这个主机，而不是最初请求的主机（如 <code class=\"docutils literal notranslate\"><span class=\"pre\">www.example.com</span></code>）。如果 <a class=\"reference internal\" href=\"#std-setting-SECURE_SSL_REDIRECT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code></a> 为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>，则该配置没有效果。</p>\n</section>\n<section id=\"secure-ssl-redirect\">\n<span id=\"std-setting-SECURE_SSL_REDIRECT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code><a class=\"heading-anchor\" href=\"#secure-ssl-redirect\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>如果 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，则 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a> <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#ssl-redirect\"><span class=\"std std-ref\">重定向</span></a> 所有非 HTTPS 的请求都会转为 HTTPS（除了那些匹配 <a class=\"reference internal\" href=\"#std-setting-SECURE_REDIRECT_EXEMPT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REDIRECT_EXEMPT</span></code></a> 中所列正则表达式的 URL）。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>如果将此设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> 会导致无限重定向，这可能意味着你的网站是在代理服务器后面运行的，并且无法判断哪些请求是安全的，哪些不是。你的代理服务器可能会设置一个头来指示安全请求；你可以通过找出该头并相应地配置 <a class=\"reference internal\" href=\"#std-setting-SECURE_PROXY_SSL_HEADER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_PROXY_SSL_HEADER</span></code></a> 设置来纠正这个问题。</p>\n</aside>\n</section>\n<section id=\"serialization-modules\">\n<span id=\"std-setting-SERIALIZATION_MODULES\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SERIALIZATION_MODULES</span></code><a class=\"heading-anchor\" href=\"#serialization-modules\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：未定义</p>\n<p>一个包含序列化器定义（以字符串形式提供）的模块字典，以该序列化类型的字符串标识符为键。例如，要定义一个 YAML 序列化器，使用：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">SERIALIZATION_MODULES</span> <span class=\"o\">=</span> <span class=\"p\">{</span><span class=\"s2\">&quot;yaml&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;path.to.yaml_serializer&quot;</span><span class=\"p\">}</span>\n</code></pre></div>\n</section>\n<section id=\"server-email\">\n<span id=\"std-setting-SERVER_EMAIL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SERVER_EMAIL</span></code><a class=\"heading-anchor\" href=\"#server-email\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'root&#64;localhost'</span></code></p>\n<p>错误消息来自的电子邮件地址，例如发送给 <a class=\"reference internal\" href=\"#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code></a> 的消息。此地址用于 <code class=\"docutils literal notranslate\"><span class=\"pre\">From:</span></code> 头，并且可以采用所选电子邮件发送协议中有效的任何格式。</p>\n<p>To build an address with a display name from variable content, see\n<a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#formatting-addresses\"><span class=\"std std-ref\">Formatting email addresses</span></a>.</p>\n<aside class=\"admonition-why-are-my-emails-sent-from-a-different-address admonition\">\n<p class=\"admonition-title\">为什么我的邮件从不同的地址发送？</p>\n<p>This address is used only for error messages. It is <em>not</em> the address that\nregular email messages sent with <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/email/#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">send_mail()</span></code></a>\ncome from; for that, see <a class=\"reference internal\" href=\"#std-setting-DEFAULT_FROM_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_FROM_EMAIL</span></code></a>.</p>\n</aside>\n</section>\n<section id=\"short-date-format\">\n<span id=\"std-setting-SHORT_DATE_FORMAT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SHORT_DATE_FORMAT</span></code><a class=\"heading-anchor\" href=\"#short-date-format\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认 ：<code class=\"docutils literal notranslate\"><span class=\"pre\">'m/d/Y'</span></code> （例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">12/31/2003</span></code>）</p>\n<p>可用于模板上显示日期字段的格式。请注意，相应的区域设置规定的格式具有更高的优先级，并将替代其使用。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">允许的日期格式字符串</span></code></a>。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_FORMAT</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-SHORT_DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SHORT_DATETIME_FORMAT</span></code></a>。</p>\n</section>\n<section id=\"short-datetime-format\">\n<span id=\"std-setting-SHORT_DATETIME_FORMAT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SHORT_DATETIME_FORMAT</span></code><a class=\"heading-anchor\" href=\"#short-datetime-format\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'m/d/Y</span> <span class=\"pre\">P'</span></code> （例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">12/31/2003</span> <span class=\"pre\">4</span> <span class=\"pre\">p.m.</span></code>）</p>\n<p>可用于模板上显示日期时间字段的格式。请注意，相应的区域设置规定的格式具有更高的优先级，并将替代其使用。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">允许的日期格式字符串</span></code></a>。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_FORMAT</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-SHORT_DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SHORT_DATE_FORMAT</span></code></a>。</p>\n</section>\n<section id=\"signed-cookie-legacy-salt-fallback\">\n<span id=\"std-setting-SIGNED_COOKIE_LEGACY_SALT_FALLBACK\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SIGNED_COOKIE_LEGACY_SALT_FALLBACK</span></code><a class=\"heading-anchor\" href=\"#signed-cookie-legacy-salt-fallback\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"version-note version-added\" data-version=\"5.2.15\">\n<p class=\"version-note-title\">New in Django 5.2.15</p></aside>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>Controls whether <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/request-response/#django.http.HttpRequest.get_signed_cookie\" title=\"django.http.HttpRequest.get_signed_cookie\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_signed_cookie()</span></code></a> accepts\ncookies signed with Django's historical signed-cookie salt derivation based on\n<code class=\"docutils literal notranslate\"><span class=\"pre\">key</span> <span class=\"pre\">+</span> <span class=\"pre\">salt</span></code>.</p>\n<p>Set this to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> to accept those legacy signed cookies in addition to\ncookies signed with Django's current unambiguous signed-cookie salt derivation.</p>\n<aside class=\"version-note version-changed\" data-version=\"6.1\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p>In older versions, the default was <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This transitional setting will be removed in Django 7.0, when legacy signed\ncookies will no longer be accepted.</p>\n</aside>\n</section>\n<section id=\"signing-backend\">\n<span id=\"std-setting-SIGNING_BACKEND\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SIGNING_BACKEND</span></code><a class=\"heading-anchor\" href=\"#signing-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.core.signing.TimestampSigner'</span></code></p>\n<p>用于签署 cookie 和其他数据的后端。</p>\n<p>另见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/signing/\"><span class=\"doc\">加密签名</span></a> 文档。</p>\n</section>\n<section id=\"silenced-system-checks\">\n<span id=\"std-setting-SILENCED_SYSTEM_CHECKS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SILENCED_SYSTEM_CHECKS</span></code><a class=\"heading-anchor\" href=\"#silenced-system-checks\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>你希望永久获取和忽略的系统检查框架生成的消息标识符列表（即 <code class=\"docutils literal notranslate\"><span class=\"pre\">[&quot;models.W001&quot;]</span></code>）。静默检查不会被输出到控制台。</p>\n<p>另见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/checks/\"><span class=\"doc\">系统检查框架</span></a> 文档。</p>\n</section>\n<section id=\"storages\">\n<span id=\"std-setting-STORAGES\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">STORAGES</span></code><a class=\"heading-anchor\" href=\"#storages\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.files.storage.FileSystemStorage&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;staticfiles&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.contrib.staticfiles.storage.StaticFilesStorage&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>一个包含所有用于 Django 的存储设置的字典。它是一个嵌套字典，其内容将存储别名映射到包含单个存储选项的字典。</p>\n<p>存储可以有您选择的任何别名。但是，有两个别名具有特殊意义：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">default</span></code> 用于 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/files/\"><span class=\"doc\">管理文件</span></a>。 <code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/files/storage/#django.core.files.storage.FileSystemStorage\" title=\"django.core.files.storage.FileSystemStorage\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.core.files.storage.FileSystemStorage</span></code></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code> 是默认的存储引擎。</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">staticfiles</span></code> 用于 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/\"><span class=\"doc\">管理静态文件</span></a>。 <code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.StaticFilesStorage\" title=\"django.contrib.staticfiles.storage.StaticFilesStorage\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.contrib.staticfiles.storage.StaticFilesStorage</span></code></a><code class=\"docutils literal notranslate\"><span class=\"pre\">'</span></code> 是默认的存储引擎。</p></li>\n</ul>\n<p>以下是定义名为 <code class=\"docutils literal notranslate\"><span class=\"pre\">example</span></code> 的自定义文件存储的示例 <code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code> 片段：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">STORAGES</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"s2\">&quot;example&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.files.storage.FileSystemStorage&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;location&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;/example&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;base_url&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;/example/&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code> 在初始化时以 <code class=\"docutils literal notranslate\"><span class=\"pre\">**kwargs</span></code> 形式传递给 <code class=\"docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code>。</p>\n<p>可以从 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/files/storage/#django.core.files.storage.storages\" title=\"django.core.files.storage.storages\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">django.core.files.storage.storages</span></code></a> 获取存储后端的可用实例。使用与 <a class=\"reference internal\" href=\"#std-setting-STORAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STORAGES</span></code></a> 中定义的后端相对应的键。</p>\n<aside class=\"admonition-is-my-value-merged-with-the-default-value admonition\">\n<p class=\"admonition-title\">我的值与默认值合并吗？</p>\n<p>定义此设置会覆盖默认值，而不会与默认值合并。</p>\n</aside>\n</section>\n<section id=\"tasks\">\n<span id=\"std-setting-TASKS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">TASKS</span></code><a class=\"heading-anchor\" href=\"#tasks\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"version-note version-added\" data-version=\"6.0\">\n<p class=\"version-note-title\">New in Django 6.0</p></aside>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.tasks.backends.immediate.ImmediateBackend&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">}</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>A dictionary containing the settings for all Task backends to be used with\nDjango. It is a nested dictionary whose contents maps backend aliases to a\ndictionary containing the options for each backend.</p>\n<p>The <a class=\"reference internal\" href=\"#std-setting-TASKS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TASKS</span></code></a> setting must configure a <code class=\"docutils literal notranslate\"><span class=\"pre\">default</span></code> backend; any number\nof additional backends may also be specified. Depending on which backend is\nused, other options may be required. The following options are available as\nstandard.</p>\n<section id=\"std-setting-TASKS-BACKEND\">\n<span id=\"id8\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code><a class=\"heading-anchor\" href=\"#std-setting-TASKS-BACKEND\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">''</span></code> （空字符串）</p>\n<p>The Tasks backend to use. The built-in backends are:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.tasks.backends.dummy.DummyBackend'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.tasks.backends.immediate.ImmediateBackend'</span></code></p></li>\n</ul>\n<p>You can use a backend that doesn't ship with Django by setting\n<a class=\"reference internal\" href=\"#std-setting-TASKS-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code></a> to a fully-qualified path of a backend\nclass (i.e. <code class=\"docutils literal notranslate\"><span class=\"pre\">mypackage.backends.whatever.WhateverBackend</span></code>).</p>\n</section>\n<section id=\"queues\">\n<span id=\"std-setting-TASKS-QUEUES\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">QUEUES</span></code><a class=\"heading-anchor\" href=\"#queues\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Default: <code class=\"docutils literal notranslate\"><span class=\"pre\">[&quot;default&quot;]</span></code></p>\n<p>Specify the queue names supported by the backend. This can be used to ensure\nTasks aren't enqueued to queues which do not exist.</p>\n<p>To disable queue name validation, set to an empty list (<code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code>).</p>\n</section>\n<section id=\"std-setting-TASKS-OPTIONS\">\n<span id=\"id9\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code><a class=\"heading-anchor\" href=\"#std-setting-TASKS-OPTIONS\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Default: <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code></p>\n<p>Extra parameters to pass to the Task backend. Available parameters vary\ndepending on the Task backend.</p>\n</section>\n</section>\n<section id=\"templates\">\n<span id=\"std-setting-TEMPLATES\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">TEMPLATES</span></code><a class=\"heading-anchor\" href=\"#templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>一个包含所有 Django 模板引擎的配置的列表。列表中的每一项都是一个字典，包含了各个引擎的选项。</p>\n<p>下面是一个配置，告诉 Django 模板引擎从每个安装好的应用程序中的 <code class=\"docutils literal notranslate\"><span class=\"pre\">templates</span></code> 子目录中加载模板：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">TEMPLATES</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.template.backends.django.DjangoTemplates&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;APP_DIRS&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>以下选项适用于所有后端。</p>\n<section id=\"std-setting-TEMPLATES-BACKEND\">\n<span id=\"id10\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code><a class=\"heading-anchor\" href=\"#std-setting-TEMPLATES-BACKEND\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认：未定义</p>\n<p>要使用的模板后端。内置的模板后端有：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.template.backends.django.DjangoTemplates'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.template.backends.jinja2.Jinja2'</span></code></p></li>\n</ul>\n<p>你可以通过将 <code class=\"docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code> 设置为一个完全限定的路径（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">'mypackage.whatever.Backend'</span></code>）来使用一个不在 Django 中的模板后端。</p>\n</section>\n<section id=\"std-setting-TEMPLATES-NAME\">\n<span id=\"id11\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">NAME</span></code><a class=\"heading-anchor\" href=\"#std-setting-TEMPLATES-NAME\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认：见下方</p>\n<p>这个特定模板引擎的别称。它是一个标识符，允许选择一个引擎进行渲染。所有配置的模板引擎的别名必须是唯一的。</p>\n<p>它默认为定义引擎类的模块名称，即 <a class=\"reference internal\" href=\"#std-setting-TEMPLATES-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">BACKEND</span></code></a> 的下一个到最后一个，如果没有提供的话。例如，如果后端是 <code class=\"docutils literal notranslate\"><span class=\"pre\">'mypackage.whatever.Backend'</span></code>，那么它的默认名称是 <code class=\"docutils literal notranslate\"><span class=\"pre\">'whatever'</span></code>。</p>\n</section>\n<section id=\"dirs\">\n<span id=\"std-setting-TEMPLATES-DIRS\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">DIRS</span></code><a class=\"heading-anchor\" href=\"#dirs\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>按照搜索顺序，引擎应该查找模板源文件的目录。</p>\n</section>\n<section id=\"app-dirs\">\n<span id=\"std-setting-TEMPLATES-APP_DIRS\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">APP_DIRS</span></code><a class=\"heading-anchor\" href=\"#app-dirs\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>引擎是否应该在已安装的应用程序中查找模板源文件。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>默认的 <code class=\"file docutils literal notranslate\"><span class=\"pre\">settings.py</span></code> 文件由 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">django-admin</span> <span class=\"pre\">startproject</span></code></a> 创建，设置 <code class=\"docutils literal notranslate\"><span class=\"pre\">'APP_DIRS':</span> <span class=\"pre\">True</span></code>。</p>\n</aside>\n</section>\n<section id=\"std-setting-TEMPLATES-OPTIONS\">\n<span id=\"id12\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">OPTIONS</span></code><a class=\"heading-anchor\" href=\"#std-setting-TEMPLATES-OPTIONS\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>默认值： <code class=\"docutils literal notranslate\"><span class=\"pre\">{}</span></code> （空字典）</p>\n<p>要传递给模板后台的额外参数。根据模板后端的不同，可用的参数也不同。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/templates/#django.template.backends.django.DjangoTemplates\" title=\"django.template.backends.django.DjangoTemplates\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">DjangoTemplates</span></code></a> 和 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/templates/#django.template.backends.jinja2.Jinja2\" title=\"django.template.backends.jinja2.Jinja2\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Jinja2</span></code></a> 了解内置后端的选项。</p>\n</section>\n</section>\n<section id=\"test-runner\">\n<span id=\"std-setting-TEST_RUNNER\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">TEST_RUNNER</span></code><a class=\"heading-anchor\" href=\"#test-runner\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.test.runner.DiscoverRunner'</span></code></p>\n<p>用于启动测试套件的类的名称。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/advanced/#other-testing-frameworks\"><span class=\"std std-ref\">使用不同的测试框架</span></a>。</p>\n</section>\n<section id=\"test-non-serialized-apps\">\n<span id=\"std-setting-TEST_NON_SERIALIZED_APPS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">TEST_NON_SERIALIZED_APPS</span></code><a class=\"heading-anchor\" href=\"#test-non-serialized-apps\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>为了在 <code class=\"docutils literal notranslate\"><span class=\"pre\">TransactionTestCase</span></code> 和没有事务的数据库后端测试之间恢复数据库状态，Django 在启动测试运行时，会 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/testing/overview/#test-case-serialized-rollback\"><span class=\"std std-ref\">序列化所有应用的内容</span></a>，这样就可以在运行需要的测试之前，从该副本重新加载。</p>\n<p>这将减慢测试运行器的启动时间；如果你有一些应用程序不需要这个功能，你可以在这里添加它们的全名（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.contenttypes'</span></code>），将它们从这个序列化过程中排除。</p>\n</section>\n<section id=\"thousand-separator\">\n<span id=\"std-setting-THOUSAND_SEPARATOR\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">THOUSAND_SEPARATOR</span></code><a class=\"heading-anchor\" href=\"#thousand-separator\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">','</span></code> （英文逗号）</p>\n<p>格式化数字时使用的默认千位分隔符。只有当 <a class=\"reference internal\" href=\"#std-setting-USE_THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_THOUSAND_SEPARATOR</span></code></a> 为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> 和 <a class=\"reference internal\" href=\"#std-setting-NUMBER_GROUPING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NUMBER_GROUPING</span></code></a> 大于 <code class=\"docutils literal notranslate\"><span class=\"pre\">0</span></code> 时，才使用此配置。</p>\n<p>请注意，由区域设置规定的格式具有更高的优先级，将会被应用。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-NUMBER_GROUPING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NUMBER_GROUPING</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-DECIMAL_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DECIMAL_SEPARATOR</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-USE_THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_THOUSAND_SEPARATOR</span></code></a>。</p>\n</section>\n<section id=\"time-format\">\n<span id=\"std-setting-TIME_FORMAT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">TIME_FORMAT</span></code><a class=\"heading-anchor\" href=\"#time-format\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'P'</span></code> （例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">4</span> <span class=\"pre\">p.m.</span></code>）</p>\n<p>在系统的任何部分用于显示时间字段的默认格式。请注意，区域设置规定的格式具有更高的优先级，并将替代其使用。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">允许的日期格式字符串</span></code></a>。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_FORMAT</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_FORMAT</span></code></a>。</p>\n</section>\n<section id=\"time-input-formats\">\n<span id=\"std-setting-TIME_INPUT_FORMATS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">TIME_INPUT_FORMATS</span></code><a class=\"heading-anchor\" href=\"#time-input-formats\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">[</span>\n    <span class=\"s2\">&quot;%H:%M:%S&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;14:30:59&#39;</span>\n    <span class=\"s2\">&quot;%H:%M:%S.</span><span class=\"si\">%f</span><span class=\"s2\">&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;14:30:59.000200&#39;</span>\n    <span class=\"s2\">&quot;%H:%M&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &#39;14:30&#39;</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>在时间字段上输入数据时可接受的格式列表。格式将按顺序被尝试，使用第一个有效的格式。注意这些格式字符串使用 Python 的 <a class=\"reference external\" href=\"https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior\" title=\"(in Python v3.14)\"><span class=\"xref std std-ref\">datetime 模块语法</span></a>，而不是来自 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">date</span></code></a> 模板过滤器的格式字符串。</p>\n<p>由区域设置规定的格式具有更高的优先级，将会被应用。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DATE_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_INPUT_FORMATS</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-DATETIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_INPUT_FORMATS</span></code></a>。</p>\n</section>\n<section id=\"std-setting-TIME_ZONE\">\n<span id=\"id13\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code><a class=\"heading-anchor\" href=\"#std-setting-TIME_ZONE\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'America/Chicago'</span></code></p>\n<p>表示本次安装的时区的字符串。参见 <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\">时区列表</a> 。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>自从 Django 首次发布时， <a class=\"reference internal\" href=\"#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a> 设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">'America/Chicago'</span></code>，为了向后兼容，全局配置（如果你的项目 <code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code> 中没有定义任何内容，则使用全局配置）仍为 <code class=\"docutils literal notranslate\"><span class=\"pre\">'America/Chicago'</span></code>。新项目模板默认为 <code class=\"docutils literal notranslate\"><span class=\"pre\">'UTC'</span></code>。</p>\n</aside>\n<p>注意，这不一定是服务器的时区。例如，一个服务器可能服务于多个 Django 网站，每个网站都有单独的时区配置。</p>\n<p>当 <a class=\"reference internal\" href=\"#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code></a> 为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> 时，这是 Django 存储所有日期时间的时区。当 <a class=\"reference internal\" href=\"#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code></a> 为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> 时，这是 Django 在模板中显示日期时间和解释表单中输入的日期时间的默认时区。</p>\n<p>在 Unix 环境下（实现了 <a class=\"reference external\" href=\"https://docs.python.org/3/library/time.html#time.tzset\" title=\"(in Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">time.tzset()</span></code></a>），Django 将 <code class=\"docutils literal notranslate\"><span class=\"pre\">os.environ['TZ']</span></code> 变量设置为你在 <a class=\"reference internal\" href=\"#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a> 配置中指定的时区。这样，你所有的视图和模型都会自动在这个时区运行。但是，如果你使用的是 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/settings/#settings-without-django-settings-module\"><span class=\"std std-ref\">手动设置配置</span></a> 中描述的手动配置选项，Django 就不会设置 <code class=\"docutils literal notranslate\"><span class=\"pre\">TZ</span></code> 环境变量。如果 Django 没有设置 <code class=\"docutils literal notranslate\"><span class=\"pre\">TZ</span></code> 环境变量，那么就需要你确保你的进程运行在正确的环境中。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>Django 无法在 Windows 环境下可靠地使用交替时区。如果你在 Windows 上运行 Django， <a class=\"reference internal\" href=\"#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a> 必须设置为与系统时区匹配。</p>\n</aside>\n</section>\n<section id=\"use-blank-choice-dash\">\n<span id=\"std-setting-USE_BLANK_CHOICE_DASH\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">USE_BLANK_CHOICE_DASH</span></code><a class=\"heading-anchor\" href=\"#use-blank-choice-dash\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"version-note version-added\" data-version=\"6.1\">\n<p class=\"version-note-title\">New in Django 6.1</p></aside>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>The default blank choice label in <code class=\"docutils literal notranslate\"><span class=\"pre\">Select</span></code> widgets was changed from\n<code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;---------&quot;</span></code> to <code class=\"docutils literal notranslate\"><span class=\"pre\">django.db.models.fields.BLANK_CHOICE_LABEL</span></code>. Set this\ntransitional setting to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> to revert to the previous label.</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.1: </span>This setting will be removed in Django 7.0. To use a custom default blank\nchoice label, override <code class=\"docutils literal notranslate\"><span class=\"pre\">django.db.models.fields.BLANK_CHOICE_LABEL</span></code> in\nthe app's <code class=\"docutils literal notranslate\"><span class=\"pre\">ready()</span></code> method.</p>\n</aside>\n</section>\n<section id=\"use-i18n\">\n<span id=\"std-setting-USE_I18N\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">USE_I18N</span></code><a class=\"heading-anchor\" href=\"#use-i18n\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code></p>\n<p>一个布尔值，用于指定是否应该启用 Django 的翻译系统。这提供了一个关闭翻译系统的方法，以保证性能。如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>，Django 会进行一些优化，以避免加载翻译机制。</p>\n<p>另请参阅 <a class=\"reference internal\" href=\"#std-setting-LANGUAGE_CODE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_CODE</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code></a>。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>默认的 <code class=\"file docutils literal notranslate\"><span class=\"pre\">settings.py</span></code> 文件由 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">django-admin</span> <span class=\"pre\">startproject</span></code></a> 创建，包括方便起见 <code class=\"docutils literal notranslate\"><span class=\"pre\">USE_I18N</span> <span class=\"pre\">=</span> <span class=\"pre\">True</span></code>。</p>\n</aside>\n</section>\n<section id=\"use-thousand-separator\">\n<span id=\"std-setting-USE_THOUSAND_SEPARATOR\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">USE_THOUSAND_SEPARATOR</span></code><a class=\"heading-anchor\" href=\"#use-thousand-separator\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>一个布尔值，指定是否使用千位分隔符显示数字。当设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> 时，Django 将使用 <a class=\"reference internal\" href=\"#std-setting-NUMBER_GROUPING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NUMBER_GROUPING</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">THOUSAND_SEPARATOR</span></code></a> 设置来格式化数字。后两个设置也可能由区域设置规定，区域设置优先。</p>\n<p>另见 <a class=\"reference internal\" href=\"#std-setting-DECIMAL_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DECIMAL_SEPARATOR</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-NUMBER_GROUPING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NUMBER_GROUPING</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">THOUSAND_SEPARATOR</span></code></a>。</p>\n</section>\n<section id=\"use-tz\">\n<span id=\"std-setting-USE_TZ\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code><a class=\"heading-anchor\" href=\"#use-tz\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code></p>\n<p>一个布尔值，用于指定 Django 是否默认使用时区感知。如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，Django 将在内部使用时区感知的日期。</p>\n<p>当 <code class=\"docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code> 为 False 时，Django 将使用本地时间的本地日期，除非在解析 ISO 8601 格式的字符串时，如果存在时区信息，则会一直保留。</p>\n<p>另请参阅 <a class=\"reference internal\" href=\"#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-USE_I18N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_I18N</span></code></a>。</p>\n</section>\n<section id=\"use-x-forwarded-host\">\n<span id=\"std-setting-USE_X_FORWARDED_HOST\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">USE_X_FORWARDED_HOST</span></code><a class=\"heading-anchor\" href=\"#use-x-forwarded-host\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>一个布尔值，用于指定是否使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">X-Forwarded-Host</span></code> 头，而不是 <code class=\"docutils literal notranslate\"><span class=\"pre\">Host</span></code> 头。只有在使用设置该头的代理时才应启用。</p>\n<p>此设置优先于 <a class=\"reference internal\" href=\"#std-setting-USE_X_FORWARDED_PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_X_FORWARDED_PORT</span></code></a>。根据 <span class=\"target\" id=\"index-4\"></span><a class=\"rfc reference external\" href=\"https://datatracker.ietf.org/doc/html/rfc7239.html#section-5.3\"><strong>RFC 7239 Section 5.3</strong></a>，<code class=\"docutils literal notranslate\"><span class=\"pre\">X-Forwarded-Host</span></code> 头可以包括端口号，在这种情况下，你不应该使用 <a class=\"reference internal\" href=\"#std-setting-USE_X_FORWARDED_PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_X_FORWARDED_PORT</span></code></a>。</p>\n</section>\n<section id=\"use-x-forwarded-port\">\n<span id=\"std-setting-USE_X_FORWARDED_PORT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">USE_X_FORWARDED_PORT</span></code><a class=\"heading-anchor\" href=\"#use-x-forwarded-port\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>一个布尔值，用于指定是否使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">X-Forwarded-Port</span></code> 头，而不是 <code class=\"docutils literal notranslate\"><span class=\"pre\">SERVER_PORT``META</span></code> 变量。只有在使用设置该头的代理时，才应启用。</p>\n<p><a class=\"reference internal\" href=\"#std-setting-USE_X_FORWARDED_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_X_FORWARDED_HOST</span></code></a> 优先于此配置。</p>\n</section>\n<section id=\"urlize-assume-https\">\n<span id=\"std-setting-URLIZE_ASSUME_HTTPS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">URLIZE_ASSUME_HTTPS</span></code><a class=\"heading-anchor\" href=\"#urlize-assume-https\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"version-note version-added\" data-version=\"6.0\">\n<p class=\"version-note-title\">New in Django 6.0</p></aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.0\">\n<p class=\"version-note-title\">Deprecated since Django 6.0</p><p><span class=\"versionmodified deprecated\">Deprecated since version 6.0.</span></p>\n</aside>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>Set this transitional setting to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> to opt into using HTTPS as the\ndefault protocol when none is provided in URLs processed by the\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-urlize\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">urlize</span></code></a> and <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-urlizetrunc\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">urlizetrunc</span></code></a> template filters during the Django\n6.x release cycle.</p>\n</section>\n<section id=\"wsgi-application\">\n<span id=\"std-setting-WSGI_APPLICATION\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">WSGI_APPLICATION</span></code><a class=\"heading-anchor\" href=\"#wsgi-application\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>Django 内置服务器（如 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#django-admin-runserver\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">runserver</span></code></a>）将使用的 WSGI 应用对象的完整 Python 路径。<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">django-admin</span> <span class=\"pre\">startproject</span></code></a> 管理命令将创建一个标准的 <code class=\"docutils literal notranslate\"><span class=\"pre\">wsgi.py</span></code> 文件，其中有一个 <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> 可调用，并将此配置指向该 <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code>。</p>\n<p>如果没有设置，将使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">django.core.wsgi.get_wsgi_application()</span></code> 的返回值。在这种情况下， <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/django-admin/#django-admin-runserver\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">runserver</span></code></a> 的行为将与之前的 Django 版本相同。</p>\n</section>\n<section id=\"year-month-format\">\n<span id=\"std-setting-YEAR_MONTH_FORMAT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">YEAR_MONTH_FORMAT</span></code><a class=\"heading-anchor\" href=\"#year-month-format\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'F</span> <span class=\"pre\">Y'</span></code></p>\n<p>在 Django admin change-list 页面中，当只显示年和月的时候，默认的日期字段的格式也可能被系统的其他部分使用。</p>\n<p>例如，当 Django 管理员的变更列表页面被日期 drilldown 过滤时，给定月份的头显示月份和年份。不同的地域有不同的格式。例如，美国英语会说“January 2006”，而另一个地方语言可能会说 “2006/January”。</p>\n<p>请注意，相应的由区域设置规定的格式具有更高的优先级，将会被应用。</p>\n<p>查看 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">允许的日期格式字符串</span></code></a>。另见 <a class=\"reference internal\" href=\"#std-setting-DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_FORMAT</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_FORMAT</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-TIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_FORMAT</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-MONTH_DAY_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MONTH_DAY_FORMAT</span></code></a>。</p>\n</section>\n<section id=\"x-frame-options\">\n<span id=\"std-setting-X_FRAME_OPTIONS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">X_FRAME_OPTIONS</span></code><a class=\"heading-anchor\" href=\"#x-frame-options\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'DENY'</span></code></p>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.middleware.clickjacking.XFrameOptionsMiddleware\" title=\"django.middleware.clickjacking.XFrameOptionsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">XFrameOptionsMiddleware</span></code></a> 使用的 X- Frame-Options 头的默认值。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/clickjacking/\"><span class=\"doc\">点击劫持保护</span></a> 文档。</p>\n</section>\n</section>\n<section id=\"auth\">\n<h2><a class=\"toc-backref\" href=\"#id17\" role=\"doc-backlink\">认证</a><a class=\"headerlink\" href=\"#auth\" title=\"Link to this heading\">¶</a></h2>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/#module-django.contrib.auth\" title=\"django.contrib.auth: Django's authentication framework.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.auth</span></code></a> 的配置。</p>\n<section id=\"authentication-backends\">\n<span id=\"std-setting-AUTHENTICATION_BACKENDS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">AUTHENTICATION_BACKENDS</span></code><a class=\"heading-anchor\" href=\"#authentication-backends\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">['django.contrib.auth.backends.ModelBackend']</span></code></p>\n<p>当试图认证用户时，要使用的认证后端类（字符串）列表。详情请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/customizing/#authentication-backends\"><span class=\"std std-ref\">认证后端文档</span></a>。</p>\n</section>\n<section id=\"auth-user-model\">\n<span id=\"std-setting-AUTH_USER_MODEL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">AUTH_USER_MODEL</span></code><a class=\"heading-anchor\" href=\"#auth-user-model\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'auth.User'</span></code></p>\n<p>用来表示用户的模型。见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/customizing/#auth-custom-user\"><span class=\"std std-ref\">替换一个自定义的 User 模型。</span></a>。</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>在项目的生命周期内（即一旦你制作并迁移了依赖它的模型），你无法不费吹灰之力地更改 AUTH_USER_MODEL 配置。它的目的是在项目开始时设置，并且它所引用的模型必须在它所在的应用程序的第一次迁移中可用。详见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/customizing/#auth-custom-user\"><span class=\"std std-ref\">替换一个自定义的 User 模型。</span></a>。</p>\n</aside>\n</section>\n<section id=\"login-redirect-url\">\n<span id=\"std-setting-LOGIN_REDIRECT_URL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LOGIN_REDIRECT_URL</span></code><a class=\"heading-anchor\" href=\"#login-redirect-url\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'/accounts/profile/'</span></code></p>\n<p>当 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/default/#django.contrib.auth.views.LoginView\" title=\"django.contrib.auth.views.LoginView\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">LoginView</span></code></a> 没有得到 <code class=\"docutils literal notranslate\"><span class=\"pre\">next</span></code> GET 参数时，登录后请求被重定向的 URL 或 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/urls/#naming-url-patterns\"><span class=\"std std-ref\">命名 URL 模式</span></a>。</p>\n</section>\n<section id=\"login-url\">\n<span id=\"std-setting-LOGIN_URL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LOGIN_URL</span></code><a class=\"heading-anchor\" href=\"#login-url\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'/accounts/login/'</span></code></p>\n<p>在使用 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/default/#django.contrib.auth.decorators.login_required\" title=\"django.contrib.auth.decorators.login_required\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">login_required()</span></code></a> 装饰器、<a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/default/#django.contrib.auth.mixins.LoginRequiredMixin\" title=\"django.contrib.auth.mixins.LoginRequiredMixin\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">LoginRequiredMixin</span></code></a>、<a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/default/#django.contrib.auth.mixins.AccessMixin\" title=\"django.contrib.auth.mixins.AccessMixin\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AccessMixin</span></code></a> 或安装 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/middleware/#django.contrib.auth.middleware.LoginRequiredMiddleware\" title=\"django.contrib.auth.middleware.LoginRequiredMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">LoginRequiredMiddleware</span></code></a> 时，请求重定向到登录的 URL 或 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/urls/#naming-url-patterns\"><span class=\"std std-ref\">命名 URL 模式</span></a>。</p>\n</section>\n<section id=\"logout-redirect-url\">\n<span id=\"std-setting-LOGOUT_REDIRECT_URL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">LOGOUT_REDIRECT_URL</span></code><a class=\"heading-anchor\" href=\"#logout-redirect-url\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>如果 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/default/#django.contrib.auth.views.LogoutView\" title=\"django.contrib.auth.views.LogoutView\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">LogoutView</span></code></a> 没有 <code class=\"docutils literal notranslate\"><span class=\"pre\">next_page</span></code> 属性，则注销后重定向请求的 URL 或 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/urls/#naming-url-patterns\"><span class=\"std std-ref\">命名 URL 模式</span></a>。</p>\n<p>如果 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，将不执行重定向，并显示注销视图。</p>\n</section>\n<section id=\"password-reset-timeout\">\n<span id=\"std-setting-PASSWORD_RESET_TIMEOUT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">PASSWORD_RESET_TIMEOUT</span></code><a class=\"heading-anchor\" href=\"#password-reset-timeout\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">259200</span></code> （3 天，以秒为单位）</p>\n<p>密码重置链接的有效秒数。</p>\n<p>由 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/default/#django.contrib.auth.views.PasswordResetConfirmView\" title=\"django.contrib.auth.views.PasswordResetConfirmView\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">PasswordResetConfirmView</span></code></a> 使用。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>减少这个超时的值并不会对攻击者强行重置密码令牌的能力产生任何影响。令牌的设计是安全的，不需要任何超时。</p>\n<p>这个超时时间的存在，是为了防止一些不太可能发生的攻击情况，比如有人访问可能包含旧的、未使用的密码重置令牌的电子邮件档案。</p>\n</aside>\n</section>\n<section id=\"password-hashers\">\n<span id=\"std-setting-PASSWORD_HASHERS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">PASSWORD_HASHERS</span></code><a class=\"heading-anchor\" href=\"#password-hashers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>查看 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/passwords/#auth-password-storage\"><span class=\"std std-ref\">Django 如何存储密码</span></a>。</p>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">[</span>\n    <span class=\"s2\">&quot;django.contrib.auth.hashers.PBKDF2PasswordHasher&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.auth.hashers.Argon2PasswordHasher&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.auth.hashers.BCryptSHA256PasswordHasher&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.auth.hashers.ScryptPasswordHasher&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n</section>\n<section id=\"auth-password-validators\">\n<span id=\"std-setting-AUTH_PASSWORD_VALIDATORS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">AUTH_PASSWORD_VALIDATORS</span></code><a class=\"heading-anchor\" href=\"#auth-password-validators\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>用于检查用户密码强度的验证器列表。更多细节请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/auth/passwords/#password-validation\"><span class=\"std std-ref\">密码验证</span></a>。默认情况下，不执行验证，所有密码都被接受。</p>\n</section>\n</section>\n<section id=\"messages\">\n<span id=\"settings-messages\"></span><h2><a class=\"toc-backref\" href=\"#id18\" role=\"doc-backlink\">消息</a><a class=\"headerlink\" href=\"#messages\" title=\"Link to this heading\">¶</a></h2>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#module-django.contrib.messages\" title=\"django.contrib.messages: Provides cookie- and session-based temporary message storage.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.messages</span></code></a> 的配置。</p>\n<section id=\"message-level\">\n<span id=\"std-setting-MESSAGE_LEVEL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MESSAGE_LEVEL</span></code><a class=\"heading-anchor\" href=\"#message-level\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">messages.INFO</span></code></p>\n<p>设置消息框架将记录的最小消息级别。详见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#message-level\"><span class=\"std std-ref\">消息级别</span></a>。</p>\n<aside class=\"admonition-avoiding-circular-imports admonition\">\n<p class=\"admonition-title\">避免循环导入</p>\n<p>如果你在配置文件中覆盖了 <code class=\"docutils literal notranslate\"><span class=\"pre\">MESSAGE_LEVEL</span></code>，并依赖任何内置的常量，你必须直接导入常量模块以避免循环导入的可能性，例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.messages</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">constants</span> <span class=\"k\">as</span> <span class=\"n\">message_constants</span>\n\n<span class=\"n\">MESSAGE_LEVEL</span> <span class=\"o\">=</span> <span class=\"n\">message_constants</span><span class=\"o\">.</span><span class=\"n\">DEBUG</span>\n</code></pre></div>\n<p>如果需要，可以直接根据上面 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#message-level-constants\"><span class=\"std std-ref\">常量表</span></a> 中的数值来指定常量的数值。</p>\n</aside>\n</section>\n<section id=\"message-storage\">\n<span id=\"std-setting-MESSAGE_STORAGE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MESSAGE_STORAGE</span></code><a class=\"heading-anchor\" href=\"#message-storage\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.messages.storage.fallback.FallbackStorage'</span></code></p>\n<p>控制 Django 存储消息数据的地方。有效值是：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.messages.storage.fallback.FallbackStorage'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.messages.storage.session.SessionStorage'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.messages.storage.cookie.CookieStorage'</span></code></p></li>\n</ul>\n<p>详见 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#message-storage-backends\"><span class=\"std std-ref\">消息储存后端</span></a>。</p>\n<p>使用 cookie 的后端—— <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#django.contrib.messages.storage.cookie.CookieStorage\" title=\"django.contrib.messages.storage.cookie.CookieStorage\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CookieStorage</span></code></a> 和 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#django.contrib.messages.storage.fallback.FallbackStorage\" title=\"django.contrib.messages.storage.fallback.FallbackStorage\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FallbackStorage</span></code></a> ——在设置它们的 cookie 时，使用 <a class=\"reference internal\" href=\"#std-setting-SESSION_COOKIE_DOMAIN\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_DOMAIN</span></code></a>、<a class=\"reference internal\" href=\"#std-setting-SESSION_COOKIE_SECURE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_SECURE</span></code></a> 和 <a class=\"reference internal\" href=\"#std-setting-SESSION_COOKIE_HTTPONLY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_HTTPONLY</span></code></a> 的值。</p>\n</section>\n<section id=\"message-tags\">\n<span id=\"std-setting-MESSAGE_TAGS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">MESSAGE_TAGS</span></code><a class=\"heading-anchor\" href=\"#message-tags\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">{</span>\n    <span class=\"n\">messages</span><span class=\"o\">.</span><span class=\"n\">DEBUG</span><span class=\"p\">:</span> <span class=\"s2\">&quot;debug&quot;</span><span class=\"p\">,</span>\n    <span class=\"n\">messages</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">:</span> <span class=\"s2\">&quot;info&quot;</span><span class=\"p\">,</span>\n    <span class=\"n\">messages</span><span class=\"o\">.</span><span class=\"n\">SUCCESS</span><span class=\"p\">:</span> <span class=\"s2\">&quot;success&quot;</span><span class=\"p\">,</span>\n    <span class=\"n\">messages</span><span class=\"o\">.</span><span class=\"n\">WARNING</span><span class=\"p\">:</span> <span class=\"s2\">&quot;warning&quot;</span><span class=\"p\">,</span>\n    <span class=\"n\">messages</span><span class=\"o\">.</span><span class=\"n\">ERROR</span><span class=\"p\">:</span> <span class=\"s2\">&quot;error&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>这设置了消息级别到消息标签的映射，通常在 HTML 中以 CSS 类的形式呈现。如果你指定了一个值，它将扩展默认值。这意味着你只需要指定那些你需要覆盖的值。更多细节请参考上面的 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#message-displaying\"><span class=\"std std-ref\">显示消息</span></a>。</p>\n<aside class=\"admonition-avoiding-circular-imports admonition\">\n<p class=\"admonition-title\">避免循环导入</p>\n<p>如果你在配置文件中覆盖了 <code class=\"docutils literal notranslate\"><span class=\"pre\">MESSAGE_TAGS</span></code>，并依赖任何内置的常量，你必须直接导入 <code class=\"docutils literal notranslate\"><span class=\"pre\">constants</span></code> 模块，以避免循环导入的可能性，例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.messages</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">constants</span> <span class=\"k\">as</span> <span class=\"n\">message_constants</span>\n\n<span class=\"n\">MESSAGE_TAGS</span> <span class=\"o\">=</span> <span class=\"p\">{</span><span class=\"n\">message_constants</span><span class=\"o\">.</span><span class=\"n\">INFO</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">}</span>\n</code></pre></div>\n<p>如果需要，可以直接根据上面 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#message-level-constants\"><span class=\"std std-ref\">常量表</span></a> 中的数值来指定常量的数值。</p>\n</aside>\n</section>\n</section>\n<section id=\"sessions\">\n<span id=\"settings-sessions\"></span><h2><a class=\"toc-backref\" href=\"#id19\" role=\"doc-backlink\">会话</a><a class=\"headerlink\" href=\"#sessions\" title=\"Link to this heading\">¶</a></h2>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/sessions/#module-django.contrib.sessions\" title=\"django.contrib.sessions: Provides session management for Django projects.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.sessions</span></code></a> 的配置。</p>\n<section id=\"session-cache-alias\">\n<span id=\"std-setting-SESSION_CACHE_ALIAS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_CACHE_ALIAS</span></code><a class=\"heading-anchor\" href=\"#session-cache-alias\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'default'</span></code></p>\n<p>如果你使用的是 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/sessions/#cached-sessions-backend\"><span class=\"std std-ref\">基于缓存的会话存储</span></a>，这将选择要使用的缓存。</p>\n</section>\n<section id=\"session-cookie-age\">\n<span id=\"std-setting-SESSION_COOKIE_AGE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_AGE</span></code><a class=\"heading-anchor\" href=\"#session-cookie-age\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">1209600</span></code> （2 周，以秒为单位）</p>\n<p>会话 cookie 的寿命，以秒为单位。</p>\n</section>\n<section id=\"session-cookie-domain\">\n<span id=\"std-setting-SESSION_COOKIE_DOMAIN\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_DOMAIN</span></code><a class=\"heading-anchor\" href=\"#session-cookie-domain\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>用于会话 cookie 的域。将其设置为一个字符串，如 <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;example.com&quot;</span></code>，用于跨域 cookie，或使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> 用于标准域 cookie。</p>\n<p>要使用带有 <a class=\"reference internal\" href=\"#std-setting-CSRF_USE_SESSIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_USE_SESSIONS</span></code></a> 的跨域 cookie，你必须包括一个前导点（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;.example.com&quot;</span></code>），以适应 CSRF 中间件的引用检查。</p>\n<p>在生产型网站上更新此配置时要谨慎。如果你更新此配置，在以前使用标准域 cookie 的网站上启用跨域 cookie，现有用户 cookie 将被设置为旧域。这可能导致他们无法登录，只要这些 cookie 持续存在。</p>\n<p>这个配置也会影响到 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/messages/#module-django.contrib.messages\" title=\"django.contrib.messages: Provides cookie- and session-based temporary message storage.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.messages</span></code></a> 所设置的 cookies。</p>\n</section>\n<section id=\"session-cookie-httponly\">\n<span id=\"std-setting-SESSION_COOKIE_HTTPONLY\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_HTTPONLY</span></code><a class=\"heading-anchor\" href=\"#session-cookie-httponly\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code></p>\n<p>是否对会话 cookie 使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpOnly</span></code> 标志。如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，客户端的 JavaScript 将无法访问会话 cookie。</p>\n<p><a class=\"reference external\" href=\"https://owasp.org/www-community/HttpOnly\">HttpOnly</a> 是包含在 Set-Cookie HTTP 响应头中的一个标志。它是 <span class=\"target\" id=\"index-5\"></span><a class=\"rfc reference external\" href=\"https://datatracker.ietf.org/doc/html/rfc6265.html#section-4.1.2.6\"><strong>RFC 6265 Section 4.1.2.6</strong></a> 标准中 Cookie 的一部分，可以作为一种有用的方式来降低客户端脚本访问受保护 Cookie 数据的风险。</p>\n<p>这使得攻击者将跨站脚本漏洞升级为完全劫持用户的会话变得不那么简单。关闭这个功能的理由不多。你的代码不应该从 JavaScript 中读取会话 cookies。</p>\n</section>\n<section id=\"session-cookie-name\">\n<span id=\"std-setting-SESSION_COOKIE_NAME\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_NAME</span></code><a class=\"heading-anchor\" href=\"#session-cookie-name\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'sessionid'</span></code></p>\n<p>用于会话的 cookie 的名称。这可以是任何你想要的（只要它与你的应用程序中的其他 cookie 名称不同）。</p>\n</section>\n<section id=\"session-cookie-path\">\n<span id=\"std-setting-SESSION_COOKIE_PATH\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_PATH</span></code><a class=\"heading-anchor\" href=\"#session-cookie-path\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'/'</span></code></p>\n<p>会话 cookie 上设置的路径。这个路径应该与你的 Django 安装的 URL 路径相匹配，或者是该路径的父路径。</p>\n<p>如果你有多个 Django 实例在同一个主机名下运行，这个功能很有用。他们可以使用不同的 cookie 路径，而且每个实例只能看到自己的会话 cookie。</p>\n</section>\n<section id=\"session-cookie-samesite\">\n<span id=\"std-setting-SESSION_COOKIE_SAMESITE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_SAMESITE</span></code><a class=\"heading-anchor\" href=\"#session-cookie-samesite\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'Lax'</span></code></p>\n<p>会话 cookie 上的 <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value\">SameSite</a> 标志的值。这个标志可以防止 cookie 在跨站请求中被发送，从而防止 CSRF 攻击，使一些窃取会话 cookie 的方法变得不可能。</p>\n<p>该配置的可能值为：</p>\n<ul>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'Strict'</span></code> ：防止浏览器在所有跨站点浏览的情况下向目标站点发送 cookie，即使在使用常规链接时也是如此。</p>\n<p>例如，对于类似 GitHub 的网站来说，这意味着如果登录的用户通过企业论坛或电子邮件链接到 GitHub 的私人项目，GitHub 将不会收到会话 cookie，用户将无法访问该项目。然而，银行网站很可能不允许从外部网站链接任何交易页面，因此 <code class=\"docutils literal notranslate\"><span class=\"pre\">'Strict'</span></code> 标志将是合适的。</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'Lax'</span></code> （默认）：为希望在用户从外部链接到达后保持用户登录会话的网站提供安全和可用性之间的平衡。</p>\n<p>在 GitHub 的场景下，当跟随外部网站的常规链接时，会话 cookie 将被允许，而在 CSRF 倾向的请求方法（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">POST</span></code>）中被阻止。</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'None'</span></code> （字符串）：会话 cookie 将随所有同站和跨站请求发送。</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> ：停用该标志。</p></li>\n</ul>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>现代浏览器为 <code class=\"docutils literal notranslate\"><span class=\"pre\">SameSite</span></code> 标志提供了一个更安全的默认策略，并将假定 <code class=\"docutils literal notranslate\"><span class=\"pre\">Lax</span></code> 为没有明确配置值的 cookies。</p>\n</aside>\n</section>\n<section id=\"session-cookie-secure\">\n<span id=\"std-setting-SESSION_COOKIE_SECURE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_SECURE</span></code><a class=\"heading-anchor\" href=\"#session-cookie-secure\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否对会话 cookie 使用安全 cookie。如果设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，cookie 将被标记为“安全”，这意味着浏览器可以确保 cookie 只在 HTTPS 连接下发送。</p>\n<p>关闭这个配置并不是一个好主意，因为攻击者可以用数据包嗅探器捕获一个未加密的会话 cookie，并使用 cookie 来劫持用户的会话</p>\n</section>\n<section id=\"session-engine\">\n<span id=\"std-setting-SESSION_ENGINE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_ENGINE</span></code><a class=\"heading-anchor\" href=\"#session-engine\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.sessions.backends.db'</span></code></p>\n<p>控制 Django 存储会话数据的地方。包括的引擎有：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.sessions.backends.db'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.sessions.backends.file'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.sessions.backends.cache'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.sessions.backends.cached_db'</span></code></p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.sessions.backends.signed_cookies'</span></code></p></li>\n</ul>\n<p>详见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/sessions/#configuring-sessions\"><span class=\"std std-ref\">配置会话引擎</span></a>。</p>\n</section>\n<section id=\"session-expire-at-browser-close\">\n<span id=\"std-setting-SESSION_EXPIRE_AT_BROWSER_CLOSE\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_EXPIRE_AT_BROWSER_CLOSE</span></code><a class=\"heading-anchor\" href=\"#session-expire-at-browser-close\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否在用户关闭浏览器时结束会话。参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/sessions/#browser-length-vs-persistent-sessions\"><span class=\"std std-ref\">浏览器长度会话与持久会话</span></a>。</p>\n</section>\n<section id=\"session-file-path\">\n<span id=\"std-setting-SESSION_FILE_PATH\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_FILE_PATH</span></code><a class=\"heading-anchor\" href=\"#session-file-path\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>如果你使用的是基于文件的会话存储，那么这个选项设置了 Django 存储会话数据的目录，当使用默认值（<code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>）时，Django 将使用系统的标准临时目录。</p>\n</section>\n<section id=\"session-save-every-request\">\n<span id=\"std-setting-SESSION_SAVE_EVERY_REQUEST\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_SAVE_EVERY_REQUEST</span></code><a class=\"heading-anchor\" href=\"#session-save-every-request\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code></p>\n<p>是否在每次请求时保存会话数据。如果这个配置是 <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> （默认），那么会话数据只有在被修改时才会被保存，也就是说，如果它的任何字典值被分配或删除，那么会话数据就会被保存。即使这个配置是活动的，也不会创建空会话。</p>\n</section>\n<section id=\"session-serializer\">\n<span id=\"std-setting-SESSION_SERIALIZER\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SESSION_SERIALIZER</span></code><a class=\"heading-anchor\" href=\"#session-serializer\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.sessions.serializers.JSONSerializer'</span></code></p>\n<p>用于序列化会话数据的序列化器类的完整导入路径。包括的序列化器是：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.sessions.serializers.JSONSerializer'</span></code></p></li>\n</ul>\n<p>参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/http/sessions/#session-serialization\"><span class=\"std std-ref\">会话序列化</span></a>。</p>\n</section>\n</section>\n<section id=\"sites\">\n<h2><a class=\"toc-backref\" href=\"#id20\" role=\"doc-backlink\">站点</a><a class=\"headerlink\" href=\"#sites\" title=\"Link to this heading\">¶</a></h2>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/sites/#module-django.contrib.sites\" title=\"django.contrib.sites: Lets you operate multiple websites from the same database and Django project\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.sites</span></code></a> 的配置。</p>\n<section id=\"site-id\">\n<span id=\"std-setting-SITE_ID\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">SITE_ID</span></code><a class=\"heading-anchor\" href=\"#site-id\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：未定义</p>\n<p>当前网站在 <code class=\"docutils literal notranslate\"><span class=\"pre\">django_site</span></code> 数据库表中的 ID，为整数。这样，应用数据就可以挂到特定的站点上，一个数据库可以管理多个站点的内容。</p>\n</section>\n</section>\n<section id=\"static-files\">\n<span id=\"settings-staticfiles\"></span><h2><a class=\"toc-backref\" href=\"#id21\" role=\"doc-backlink\">静态文件</a><a class=\"headerlink\" href=\"#static-files\" title=\"Link to this heading\">¶</a></h2>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#module-django.contrib.staticfiles\" title=\"django.contrib.staticfiles: An app for handling static files.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.staticfiles</span></code></a> 的配置。</p>\n<section id=\"static-root\">\n<span id=\"std-setting-STATIC_ROOT\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code><a class=\"heading-anchor\" href=\"#static-root\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> 将收集静态文件进行部署的目录的绝对路径。</p>\n<p>例如： <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;/var/www/example.com/static/&quot;</span></code></p>\n<p>如果 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/\"><span class=\"doc\">staticfiles</span></a> contrib 应用已启用（如在默认的项目模板中）， <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> 管理命令将收集静态文件到这个目录。更多使用方法请参见 <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/static-files/\"><span class=\"doc\">管理静态文件</span></a> 的操作指南。</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>This should be an initially empty destination directory for collecting\nyour static files from their permanent locations into one directory for\nease of deployment; it is <strong>not</strong> a place to store your static files\npermanently. You should do that in directories that will be found by\n<a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/\"><span class=\"doc\">staticfiles</span></a>’s\n<a class=\"reference internal\" href=\"#std-setting-STATICFILES_FINDERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">finders</span></code></a>, which by default, are\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'static/'</span></code> app sub-directories and any directories you include in\n<a class=\"reference internal\" href=\"#std-setting-STATICFILES_DIRS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATICFILES_DIRS</span></code></a>.</p>\n</aside>\n</section>\n<section id=\"static-url\">\n<span id=\"std-setting-STATIC_URL\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">STATIC_URL</span></code><a class=\"heading-anchor\" href=\"#static-url\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code></p>\n<p>引用位于 <a class=\"reference internal\" href=\"#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> 中的静态文件时要使用的 URL。</p>\n<p>示例：<code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;static/&quot;</span></code> 或 <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;https://static.example.com/&quot;</span></code></p>\n<p>如果不是 <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>，这将被用作 <a class=\"reference internal\" href=\"/zh-hans/6.1/topics/forms/media/#form-asset-paths\"><span class=\"std std-ref\">资源定义</span></a> （<code class=\"docutils literal notranslate\"><span class=\"pre\">Media</span></code> 类）和 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/\"><span class=\"doc\">静态文件应用</span></a> 的基本路径。</p>\n<p>如果设置为非空值，必须以斜线结束。</p>\n<p>你可能需要 <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/static-files/#serving-static-files-in-development\"><span class=\"std std-ref\">在开发中服务这些文件</span></a>，在 <a class=\"reference internal\" href=\"/zh-hans/6.1/howto/static-files/deployment/\"><span class=\"doc\">生产中</span></a> 肯定需要这样做。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>如果 <a class=\"reference internal\" href=\"#std-setting-STATIC_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_URL</span></code></a> 是一个相对路径，那么它将以服务器提供的 <code class=\"docutils literal notranslate\"><span class=\"pre\">SCRIPT_NAME</span></code> 的值为前缀（如果没有设置，则为 <code class=\"docutils literal notranslate\"><span class=\"pre\">/</span></code>）。这使得在子路径中服务 Django 应用时更容易，而无需在增加额外的配置。</p>\n</aside>\n</section>\n<section id=\"staticfiles-dirs\">\n<span id=\"std-setting-STATICFILES_DIRS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">STATICFILES_DIRS</span></code><a class=\"heading-anchor\" href=\"#staticfiles-dirs\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认： <code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> （空列表）</p>\n<p>这个配置定义了静态文件应用在启用 <code class=\"docutils literal notranslate\"><span class=\"pre\">FileSystemFinder</span></code> 查找器时将穿越的额外位置，例如，如果你使用 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> 或 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django-admin-findstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">findstatic</span></code></a> 管理命令或使用静态文件服务视图。</p>\n<p>这应该被设置为包含附加文件目录完整路径的字符串列表，例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">STATICFILES_DIRS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;/home/special.polls.com/polls/static&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;/home/polls.com/polls/static&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;/opt/webfiles/common&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>请注意，这些路径应该使用 Unix 风格的斜线，即使在 Windows 上也是如此（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;C:/Users/user/mysite/extra_static_content&quot;</span></code>）。</p>\n<section id=\"prefixes-optional\">\n<span id=\"staticfiles-dirs-prefixes\"></span><h4>前缀（可选）<a class=\"heading-anchor\" href=\"#prefixes-optional\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>如果你想用一个额外的命名空间来引用其中一个位置的文件，你可以 <strong>可选的</strong> 提供一个前缀作为 <code class=\"docutils literal notranslate\"><span class=\"pre\">(prefix,</span> <span class=\"pre\">path)</span></code> 的元组，例如：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">STATICFILES_DIRS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;downloads&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;/opt/webfiles/stats&quot;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>例如，假设你已经将 <a class=\"reference internal\" href=\"#std-setting-STATIC_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_URL</span></code></a> 设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">'static/'</span></code>，那么 <a class=\"reference internal\" href=\"/zh-hans/6.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> 管理命令将会在 <a class=\"reference internal\" href=\"#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> 的 <code class=\"docutils literal notranslate\"><span class=\"pre\">'downloads'</span></code> 子目录中收集 &quot;stats&quot; 文件。</p>\n<p>这将允许你在你的模板中用 <code class=\"docutils literal notranslate\"><span class=\"pre\">'/static/downloads/polls_20101022.tar.gz'</span></code> 引用本地文件 <code class=\"docutils literal notranslate\"><span class=\"pre\">'/opt/webfiles/stats/polls_20101022.tar.gz'</span></code>，例如：</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{%</span> <span class=\"k\">static</span> <span class=\"s1\">&#39;downloads/polls_20101022.tar.gz&#39;</span> <span class=\"cp\">%}</span><span class=\"s\">&quot;</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"staticfiles-finders\">\n<span id=\"std-setting-STATICFILES_FINDERS\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">STATICFILES_FINDERS</span></code><a class=\"heading-anchor\" href=\"#staticfiles-finders\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>默认：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">[</span>\n    <span class=\"s2\">&quot;django.contrib.staticfiles.finders.FileSystemFinder&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.staticfiles.finders.AppDirectoriesFinder&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>知道如何找到不同位置的静态文件的查找器后端列表。</p>\n<p>默认情况下，将查找存储在 <a class=\"reference internal\" href=\"#std-setting-STATICFILES_DIRS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATICFILES_DIRS</span></code></a> 配置中的文件（使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.staticfiles.finders.FileSystemFinder</span></code>）和每个应用程序的 <code class=\"docutils literal notranslate\"><span class=\"pre\">static</span></code> 子目录中的文件（使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.staticfiles.finders.AppDirectoriesFinder</span></code>）。如果存在多个同名文件，将使用第一个找到的文件。</p>\n<p>默认情况下，一个查找器是禁用的：<code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.staticfiles.finders.DefaultStorageFinder</span></code>。如果将其添加到 <a class=\"reference internal\" href=\"#std-setting-STATICFILES_FINDERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATICFILES_FINDERS</span></code></a> 设置中，它将在 <a class=\"reference internal\" href=\"#std-setting-STORAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STORAGES</span></code></a> 设置中的 <code class=\"docutils literal notranslate\"><span class=\"pre\">default</span></code> 键定义的默认文件存储中查找静态文件。</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>当使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">AppDirectoriesFinder</span></code> 查找器时，通过将应用添加到你的网站的 <a class=\"reference internal\" href=\"#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> 配置中，确保你的应用程序可以通过 staticfiles 找到。</p>\n</aside>\n<p>静态文件查找器目前被认为是一个私有接口，因此这个接口是没有文档的。</p>\n</section>\n</section>\n<section id=\"core-settings-topical-index\">\n<h2><a class=\"toc-backref\" href=\"#id22\" role=\"doc-backlink\">核心配置专题索引</a><a class=\"headerlink\" href=\"#core-settings-topical-index\" title=\"Link to this heading\">¶</a></h2>\n<section id=\"cache\">\n<h3>缓存<a class=\"heading-anchor\" href=\"#cache\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-CACHES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CACHES</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CACHE_MIDDLEWARE_ALIAS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CACHE_MIDDLEWARE_ALIAS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CACHE_MIDDLEWARE_KEY_PREFIX\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CACHE_MIDDLEWARE_KEY_PREFIX</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CACHE_MIDDLEWARE_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CACHE_MIDDLEWARE_SECONDS</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"database\">\n<h3>数据库<a class=\"heading-anchor\" href=\"#database\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATABASE_ROUTERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASE_ROUTERS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEFAULT_INDEX_TABLESPACE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_INDEX_TABLESPACE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEFAULT_TABLESPACE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_TABLESPACE</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"debugging\">\n<h3>调试<a class=\"heading-anchor\" href=\"#debugging\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEBUG_PROPAGATE_EXCEPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG_PROPAGATE_EXCEPTIONS</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"email\">\n<h3>电子邮件<a class=\"heading-anchor\" href=\"#email\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEFAULT_CHARSET\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_CHARSET</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEFAULT_FROM_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_FROM_EMAIL</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_BACKEND</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_FILE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_FILE_PATH</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_HOST_PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST_PASSWORD</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_HOST_USER</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_PORT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_SSL_CERTFILE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_SSL_CERTFILE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_SSL_KEYFILE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_SSL_KEYFILE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_SUBJECT_PREFIX\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_SUBJECT_PREFIX</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_TIMEOUT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_TIMEOUT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_LOCALTIME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_LOCALTIME</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_SSL</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-EMAIL_USE_TLS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_USE_TLS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MAILERS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SERVER_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SERVER_EMAIL</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"error-reporting\">\n<h3>发送错误<a class=\"heading-anchor\" href=\"#error-reporting\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEFAULT_EXCEPTION_REPORTER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_EXCEPTION_REPORTER</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEFAULT_EXCEPTION_REPORTER_FILTER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-IGNORABLE_404_URLS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">IGNORABLE_404_URLS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SILENCED_SYSTEM_CHECKS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SILENCED_SYSTEM_CHECKS</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"file-uploads\">\n<span id=\"file-upload-settings\"></span><h3>文件上传<a class=\"heading-anchor\" href=\"#file-uploads\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-FILE_UPLOAD_HANDLERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_HANDLERS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-FILE_UPLOAD_MAX_MEMORY_SIZE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_MAX_MEMORY_SIZE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-FILE_UPLOAD_DIRECTORY_PERMISSIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_DIRECTORY_PERMISSIONS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-FILE_UPLOAD_PERMISSIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_PERMISSIONS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-FILE_UPLOAD_TEMP_DIR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FILE_UPLOAD_TEMP_DIR</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_URL</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-STORAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STORAGES</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"forms\">\n<h3>表单<a class=\"heading-anchor\" href=\"#forms\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-FORM_RENDERER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FORM_RENDERER</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-USE_BLANK_CHOICE_DASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_BLANK_CHOICE_DASH</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"globalization-i18n-l10n\">\n<h3>国际化（<code class=\"docutils literal notranslate\"><span class=\"pre\">i18n</span></code> ／ <code class=\"docutils literal notranslate\"><span class=\"pre\">l10n</span></code>）<a class=\"heading-anchor\" href=\"#globalization-i18n-l10n\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"internationalization-i18n\">\n<span id=\"settings-i18n\"></span><h4>国际化（<code class=\"docutils literal notranslate\"><span class=\"pre\">i18n</span></code>）<a class=\"heading-anchor\" href=\"#internationalization-i18n\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-FIRST_DAY_OF_WEEK\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FIRST_DAY_OF_WEEK</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-FORMAT_MODULE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FORMAT_MODULE_PATH</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGE_COOKIE_AGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_AGE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGE_COOKIE_DOMAIN\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_DOMAIN</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGE_COOKIE_HTTPONLY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_HTTPONLY</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGE_COOKIE_NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_NAME</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGE_COOKIE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_PATH</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGE_COOKIE_SAMESITE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_SAMESITE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGE_COOKIE_SECURE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_COOKIE_SECURE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGES</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGES_BIDI\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGES_BIDI</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LOCALE_PATHS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOCALE_PATHS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-USE_I18N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_I18N</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-USE_TZ\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_TZ</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"localization-l10n\">\n<span id=\"settings-l10n\"></span><h4>本地化（<code class=\"docutils literal notranslate\"><span class=\"pre\">l10n</span></code>）<a class=\"heading-anchor\" href=\"#localization-l10n\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATE_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATE_INPUT_FORMATS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATETIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATETIME_INPUT_FORMATS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DECIMAL_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DECIMAL_SEPARATOR</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LANGUAGE_CODE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LANGUAGE_CODE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-MONTH_DAY_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MONTH_DAY_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-NUMBER_GROUPING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">NUMBER_GROUPING</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SHORT_DATE_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SHORT_DATE_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SHORT_DATETIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SHORT_DATETIME_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">THOUSAND_SEPARATOR</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-TIME_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_FORMAT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-TIME_INPUT_FORMATS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_INPUT_FORMATS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-USE_THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_THOUSAND_SEPARATOR</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-YEAR_MONTH_FORMAT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">YEAR_MONTH_FORMAT</span></code></a></p></li>\n</ul>\n</section>\n</section>\n<section id=\"http\">\n<h3>HTTP<a class=\"heading-anchor\" href=\"#http\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATA_UPLOAD_MAX_MEMORY_SIZE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATA_UPLOAD_MAX_MEMORY_SIZE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATA_UPLOAD_MAX_NUMBER_FIELDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATA_UPLOAD_MAX_NUMBER_FIELDS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DATA_UPLOAD_MAX_NUMBER_FILES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATA_UPLOAD_MAX_NUMBER_FILES</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEFAULT_CHARSET\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_CHARSET</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-DISALLOWED_USER_AGENTS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DISALLOWED_USER_AGENTS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-FORCE_SCRIPT_NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FORCE_SCRIPT_NAME</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-INTERNAL_IPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INTERNAL_IPS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a></p></li>\n<li><p>安全</p>\n<ul>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_CONTENT_TYPE_NOSNIFF\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CONTENT_TYPE_NOSNIFF</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_CROSS_ORIGIN_OPENER_POLICY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CROSS_ORIGIN_OPENER_POLICY</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_CSP\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CSP</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_CSP_REPORT_ONLY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CSP_REPORT_ONLY</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_HSTS_INCLUDE_SUBDOMAINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_INCLUDE_SUBDOMAINS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_HSTS_PRELOAD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_PRELOAD</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_PROXY_SSL_HEADER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_PROXY_SSL_HEADER</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_REDIRECT_EXEMPT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REDIRECT_EXEMPT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_REFERRER_POLICY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REFERRER_POLICY</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_SSL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_HOST</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECURE_SSL_REDIRECT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code></a></p></li>\n</ul>\n</li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SIGNED_COOKIE_LEGACY_SALT_FALLBACK\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SIGNED_COOKIE_LEGACY_SALT_FALLBACK</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SIGNING_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SIGNING_BACKEND</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-USE_X_FORWARDED_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_X_FORWARDED_HOST</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-USE_X_FORWARDED_PORT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_X_FORWARDED_PORT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-WSGI_APPLICATION\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">WSGI_APPLICATION</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"id14\">\n<h3>日志<a class=\"heading-anchor\" href=\"#id14\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-LOGGING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-LOGGING_CONFIG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING_CONFIG</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"models\">\n<h3>模型<a class=\"heading-anchor\" href=\"#models\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-ABSOLUTE_URL_OVERRIDES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ABSOLUTE_URL_OVERRIDES</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-FIXTURE_DIRS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FIXTURE_DIRS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"security\">\n<h3>安全<a class=\"heading-anchor\" href=\"#security\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p>跨网站请求伪造保护</p>\n<ul>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CSRF_COOKIE_DOMAIN\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_DOMAIN</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CSRF_COOKIE_NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_NAME</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CSRF_COOKIE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_PATH</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CSRF_COOKIE_SAMESITE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_SAMESITE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CSRF_COOKIE_SECURE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_SECURE</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CSRF_FAILURE_VIEW\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_FAILURE_VIEW</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CSRF_HEADER_NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_HEADER_NAME</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CSRF_TRUSTED_ORIGINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_TRUSTED_ORIGINS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-CSRF_USE_SESSIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_USE_SESSIONS</span></code></a></p></li>\n</ul>\n</li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECRET_KEY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SECRET_KEY_FALLBACKS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY_FALLBACKS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-URLIZE_ASSUME_HTTPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">URLIZE_ASSUME_HTTPS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-X_FRAME_OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">X_FRAME_OPTIONS</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"serialization\">\n<h3>序列化<a class=\"heading-anchor\" href=\"#serialization\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-DEFAULT_CHARSET\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_CHARSET</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-SERIALIZATION_MODULES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SERIALIZATION_MODULES</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"id15\">\n<h3>模板<a class=\"heading-anchor\" href=\"#id15\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-TEMPLATES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TEMPLATES</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"testing\">\n<h3>测试中<a class=\"heading-anchor\" href=\"#testing\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p>数据库： <a class=\"reference internal\" href=\"#std-setting-DATABASE-TEST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TEST</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-TEST_NON_SERIALIZED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TEST_NON_SERIALIZED_APPS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-TEST_RUNNER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TEST_RUNNER</span></code></a></p></li>\n</ul>\n</section>\n<section id=\"urls\">\n<h3>URL<a class=\"heading-anchor\" href=\"#urls\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-PREPEND_WWW\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PREPEND_WWW</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#std-setting-ROOT_URLCONF\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ROOT_URLCONF</span></code></a></p></li>\n</ul>\n</section>\n</section>","rootId":"settings","toc":[{"title":"核心配置","anchor":"core-settings","children":[{"title":"ABSOLUTE_URL_OVERRIDES","anchor":"absolute-url-overrides","children":[]},{"title":"ADMINS","anchor":"admins","children":[]},{"title":"ALLOWED_HOSTS","anchor":"allowed-hosts","children":[]},{"title":"APPEND_SLASH","anchor":"append-slash","children":[]},{"title":"CACHES","anchor":"caches","children":[{"title":"BACKEND","anchor":"backend","children":[]},{"title":"KEY_FUNCTION","anchor":"key-function","children":[]},{"title":"KEY_PREFIX","anchor":"key-prefix","children":[]},{"title":"LOCATION","anchor":"location","children":[]},{"title":"OPTIONS","anchor":"options","children":[]},{"title":"TIMEOUT","anchor":"timeout","children":[]},{"title":"VERSION","anchor":"version","children":[]}]},{"title":"CACHE_MIDDLEWARE_ALIAS","anchor":"cache-middleware-alias","children":[]},{"title":"CACHE_MIDDLEWARE_KEY_PREFIX","anchor":"cache-middleware-key-prefix","children":[]},{"title":"CACHE_MIDDLEWARE_SECONDS","anchor":"cache-middleware-seconds","children":[]},{"title":"CSRF_COOKIE_AGE","anchor":"csrf-cookie-age","children":[]},{"title":"CSRF_COOKIE_DOMAIN","anchor":"csrf-cookie-domain","children":[]},{"title":"CSRF_COOKIE_HTTPONLY","anchor":"csrf-cookie-httponly","children":[]},{"title":"CSRF_COOKIE_NAME","anchor":"csrf-cookie-name","children":[]},{"title":"CSRF_COOKIE_PATH","anchor":"csrf-cookie-path","children":[]},{"title":"CSRF_COOKIE_SAMESITE","anchor":"csrf-cookie-samesite","children":[]},{"title":"CSRF_COOKIE_SECURE","anchor":"csrf-cookie-secure","children":[]},{"title":"CSRF_USE_SESSIONS","anchor":"csrf-use-sessions","children":[]},{"title":"CSRF_FAILURE_VIEW","anchor":"csrf-failure-view","children":[]},{"title":"CSRF_HEADER_NAME","anchor":"csrf-header-name","children":[]},{"title":"CSRF_TRUSTED_ORIGINS","anchor":"csrf-trusted-origins","children":[]},{"title":"DATABASES","anchor":"databases","children":[{"title":"ATOMIC_REQUESTS","anchor":"atomic-requests","children":[]},{"title":"AUTOCOMMIT","anchor":"autocommit","children":[]},{"title":"ENGINE","anchor":"engine","children":[]},{"title":"HOST","anchor":"host","children":[]},{"title":"NAME","anchor":"name","children":[]},{"title":"CONN_MAX_AGE","anchor":"conn-max-age","children":[]},{"title":"CONN_HEALTH_CHECKS","anchor":"conn-health-checks","children":[]},{"title":"OPTIONS","anchor":"std-setting-OPTIONS","children":[]},{"title":"PASSWORD","anchor":"password","children":[]},{"title":"PORT","anchor":"port","children":[]},{"title":"TIME_ZONE","anchor":"time-zone","children":[]},{"title":"DISABLE_SERVER_SIDE_CURSORS","anchor":"disable-server-side-cursors","children":[]},{"title":"USER","anchor":"user","children":[]},{"title":"TEST","anchor":"test","children":[{"title":"CHARSET","anchor":"charset","children":[]},{"title":"COLLATION","anchor":"collation","children":[]},{"title":"DEPENDENCIES","anchor":"dependencies","children":[]},{"title":"MIGRATE","anchor":"migrate","children":[]},{"title":"MIRROR","anchor":"mirror","children":[]},{"title":"NAME","anchor":"std-setting-TEST_NAME","children":[]},{"title":"TEMPLATE","anchor":"template","children":[]},{"title":"CREATE_DB","anchor":"create-db","children":[]},{"title":"CREATE_USER","anchor":"create-user","children":[]},{"title":"USER","anchor":"std-setting-TEST_USER","children":[]},{"title":"PASSWORD","anchor":"std-setting-TEST_PASSWD","children":[]},{"title":"ORACLE_MANAGED_FILES","anchor":"oracle-managed-files","children":[]},{"title":"TBLSPACE","anchor":"tblspace","children":[]},{"title":"TBLSPACE_TMP","anchor":"tblspace-tmp","children":[]},{"title":"DATAFILE","anchor":"datafile","children":[]},{"title":"DATAFILE_TMP","anchor":"datafile-tmp","children":[]},{"title":"DATAFILE_MAXSIZE","anchor":"datafile-maxsize","children":[]},{"title":"DATAFILE_TMP_MAXSIZE","anchor":"datafile-tmp-maxsize","children":[]},{"title":"DATAFILE_SIZE","anchor":"datafile-size","children":[]},{"title":"DATAFILE_TMP_SIZE","anchor":"datafile-tmp-size","children":[]},{"title":"DATAFILE_EXTSIZE","anchor":"datafile-extsize","children":[]},{"title":"DATAFILE_TMP_EXTSIZE","anchor":"datafile-tmp-extsize","children":[]}]}]},{"title":"DATA_UPLOAD_MAX_MEMORY_SIZE","anchor":"data-upload-max-memory-size","children":[]},{"title":"DATA_UPLOAD_MAX_NUMBER_FIELDS","anchor":"data-upload-max-number-fields","children":[]},{"title":"DATA_UPLOAD_MAX_NUMBER_FILES","anchor":"data-upload-max-number-files","children":[]},{"title":"DATABASE_ROUTERS","anchor":"database-routers","children":[]},{"title":"DATE_FORMAT","anchor":"date-format","children":[]},{"title":"DATE_INPUT_FORMATS","anchor":"date-input-formats","children":[]},{"title":"DATETIME_FORMAT","anchor":"datetime-format","children":[]},{"title":"DATETIME_INPUT_FORMATS","anchor":"datetime-input-formats","children":[]},{"title":"DEBUG","anchor":"debug","children":[]},{"title":"DEBUG_PROPAGATE_EXCEPTIONS","anchor":"debug-propagate-exceptions","children":[]},{"title":"DECIMAL_SEPARATOR","anchor":"decimal-separator","children":[]},{"title":"DEFAULT_AUTO_FIELD","anchor":"default-auto-field","children":[]},{"title":"DEFAULT_CHARSET","anchor":"default-charset","children":[]},{"title":"DEFAULT_EXCEPTION_REPORTER","anchor":"default-exception-reporter","children":[]},{"title":"DEFAULT_EXCEPTION_REPORTER_FILTER","anchor":"default-exception-reporter-filter","children":[]},{"title":"DEFAULT_FROM_EMAIL","anchor":"default-from-email","children":[]},{"title":"DEFAULT_INDEX_TABLESPACE","anchor":"default-index-tablespace","children":[]},{"title":"DEFAULT_TABLESPACE","anchor":"default-tablespace","children":[]},{"title":"DISALLOWED_USER_AGENTS","anchor":"disallowed-user-agents","children":[]},{"title":"EMAIL_BACKEND","anchor":"email-backend","children":[]},{"title":"EMAIL_FILE_PATH","anchor":"email-file-path","children":[]},{"title":"EMAIL_HOST","anchor":"email-host","children":[]},{"title":"EMAIL_HOST_PASSWORD","anchor":"email-host-password","children":[]},{"title":"EMAIL_HOST_USER","anchor":"email-host-user","children":[]},{"title":"EMAIL_PORT","anchor":"email-port","children":[]},{"title":"EMAIL_SUBJECT_PREFIX","anchor":"email-subject-prefix","children":[]},{"title":"EMAIL_USE_LOCALTIME","anchor":"email-use-localtime","children":[]},{"title":"EMAIL_USE_TLS","anchor":"email-use-tls","children":[]},{"title":"EMAIL_USE_SSL","anchor":"email-use-ssl","children":[]},{"title":"EMAIL_SSL_CERTFILE","anchor":"email-ssl-certfile","children":[]},{"title":"EMAIL_SSL_KEYFILE","anchor":"email-ssl-keyfile","children":[]},{"title":"EMAIL_TIMEOUT","anchor":"email-timeout","children":[]},{"title":"FILE_UPLOAD_HANDLERS","anchor":"file-upload-handlers","children":[]},{"title":"FILE_UPLOAD_MAX_MEMORY_SIZE","anchor":"file-upload-max-memory-size","children":[]},{"title":"FILE_UPLOAD_DIRECTORY_PERMISSIONS","anchor":"file-upload-directory-permissions","children":[]},{"title":"FILE_UPLOAD_PERMISSIONS","anchor":"file-upload-permissions","children":[]},{"title":"FILE_UPLOAD_TEMP_DIR","anchor":"file-upload-temp-dir","children":[]},{"title":"FIRST_DAY_OF_WEEK","anchor":"first-day-of-week","children":[]},{"title":"FIXTURE_DIRS","anchor":"fixture-dirs","children":[]},{"title":"FORCE_SCRIPT_NAME","anchor":"force-script-name","children":[]},{"title":"FORM_RENDERER","anchor":"form-renderer","children":[]},{"title":"FORMAT_MODULE_PATH","anchor":"format-module-path","children":[]},{"title":"IGNORABLE_404_URLS","anchor":"ignorable-404-urls","children":[]},{"title":"INSTALLED_APPS","anchor":"installed-apps","children":[]},{"title":"INTERNAL_IPS","anchor":"internal-ips","children":[]},{"title":"LANGUAGE_CODE","anchor":"language-code","children":[]},{"title":"LANGUAGE_COOKIE_AGE","anchor":"language-cookie-age","children":[]},{"title":"LANGUAGE_COOKIE_DOMAIN","anchor":"language-cookie-domain","children":[]},{"title":"LANGUAGE_COOKIE_HTTPONLY","anchor":"language-cookie-httponly","children":[]},{"title":"LANGUAGE_COOKIE_NAME","anchor":"language-cookie-name","children":[]},{"title":"LANGUAGE_COOKIE_PATH","anchor":"language-cookie-path","children":[]},{"title":"LANGUAGE_COOKIE_SAMESITE","anchor":"language-cookie-samesite","children":[]},{"title":"LANGUAGE_COOKIE_SECURE","anchor":"language-cookie-secure","children":[]},{"title":"LANGUAGES","anchor":"languages","children":[]},{"title":"LANGUAGES_BIDI","anchor":"languages-bidi","children":[]},{"title":"LOCALE_PATHS","anchor":"locale-paths","children":[]},{"title":"LOGGING","anchor":"logging","children":[]},{"title":"LOGGING_CONFIG","anchor":"logging-config","children":[]},{"title":"MAILERS","anchor":"mailers","children":[{"title":"BACKEND","anchor":"std-setting-MAILERS-BACKEND","children":[]},{"title":"OPTIONS","anchor":"std-setting-MAILERS-OPTIONS","children":[]}]},{"title":"MANAGERS","anchor":"managers","children":[]},{"title":"MEDIA_ROOT","anchor":"media-root","children":[]},{"title":"MEDIA_URL","anchor":"media-url","children":[]},{"title":"MIDDLEWARE","anchor":"middleware","children":[]},{"title":"MIGRATION_MODULES","anchor":"migration-modules","children":[]},{"title":"MONTH_DAY_FORMAT","anchor":"month-day-format","children":[]},{"title":"NUMBER_GROUPING","anchor":"number-grouping","children":[]},{"title":"PREPEND_WWW","anchor":"prepend-www","children":[]},{"title":"ROOT_URLCONF","anchor":"root-urlconf","children":[]},{"title":"SECRET_KEY","anchor":"secret-key","children":[]},{"title":"SECRET_KEY_FALLBACKS","anchor":"secret-key-fallbacks","children":[]},{"title":"SECURE_CONTENT_TYPE_NOSNIFF","anchor":"secure-content-type-nosniff","children":[]},{"title":"SECURE_CROSS_ORIGIN_OPENER_POLICY","anchor":"secure-cross-origin-opener-policy","children":[]},{"title":"SECURE_CSP","anchor":"secure-csp","children":[]},{"title":"SECURE_CSP_REPORT_ONLY","anchor":"secure-csp-report-only","children":[]},{"title":"SECURE_HSTS_INCLUDE_SUBDOMAINS","anchor":"secure-hsts-include-subdomains","children":[]},{"title":"SECURE_HSTS_PRELOAD","anchor":"secure-hsts-preload","children":[]},{"title":"SECURE_HSTS_SECONDS","anchor":"secure-hsts-seconds","children":[]},{"title":"SECURE_PROXY_SSL_HEADER","anchor":"secure-proxy-ssl-header","children":[]},{"title":"SECURE_REDIRECT_EXEMPT","anchor":"secure-redirect-exempt","children":[]},{"title":"SECURE_REFERRER_POLICY","anchor":"secure-referrer-policy","children":[]},{"title":"SECURE_SSL_HOST","anchor":"secure-ssl-host","children":[]},{"title":"SECURE_SSL_REDIRECT","anchor":"secure-ssl-redirect","children":[]},{"title":"SERIALIZATION_MODULES","anchor":"serialization-modules","children":[]},{"title":"SERVER_EMAIL","anchor":"server-email","children":[]},{"title":"SHORT_DATE_FORMAT","anchor":"short-date-format","children":[]},{"title":"SHORT_DATETIME_FORMAT","anchor":"short-datetime-format","children":[]},{"title":"SIGNED_COOKIE_LEGACY_SALT_FALLBACK","anchor":"signed-cookie-legacy-salt-fallback","children":[]},{"title":"SIGNING_BACKEND","anchor":"signing-backend","children":[]},{"title":"SILENCED_SYSTEM_CHECKS","anchor":"silenced-system-checks","children":[]},{"title":"STORAGES","anchor":"storages","children":[]},{"title":"TASKS","anchor":"tasks","children":[{"title":"BACKEND","anchor":"std-setting-TASKS-BACKEND","children":[]},{"title":"QUEUES","anchor":"queues","children":[]},{"title":"OPTIONS","anchor":"std-setting-TASKS-OPTIONS","children":[]}]},{"title":"TEMPLATES","anchor":"templates","children":[{"title":"BACKEND","anchor":"std-setting-TEMPLATES-BACKEND","children":[]},{"title":"NAME","anchor":"std-setting-TEMPLATES-NAME","children":[]},{"title":"DIRS","anchor":"dirs","children":[]},{"title":"APP_DIRS","anchor":"app-dirs","children":[]},{"title":"OPTIONS","anchor":"std-setting-TEMPLATES-OPTIONS","children":[]}]},{"title":"TEST_RUNNER","anchor":"test-runner","children":[]},{"title":"TEST_NON_SERIALIZED_APPS","anchor":"test-non-serialized-apps","children":[]},{"title":"THOUSAND_SEPARATOR","anchor":"thousand-separator","children":[]},{"title":"TIME_FORMAT","anchor":"time-format","children":[]},{"title":"TIME_INPUT_FORMATS","anchor":"time-input-formats","children":[]},{"title":"TIME_ZONE","anchor":"std-setting-TIME_ZONE","children":[]},{"title":"USE_BLANK_CHOICE_DASH","anchor":"use-blank-choice-dash","children":[]},{"title":"USE_I18N","anchor":"use-i18n","children":[]},{"title":"USE_THOUSAND_SEPARATOR","anchor":"use-thousand-separator","children":[]},{"title":"USE_TZ","anchor":"use-tz","children":[]},{"title":"USE_X_FORWARDED_HOST","anchor":"use-x-forwarded-host","children":[]},{"title":"USE_X_FORWARDED_PORT","anchor":"use-x-forwarded-port","children":[]},{"title":"URLIZE_ASSUME_HTTPS","anchor":"urlize-assume-https","children":[]},{"title":"WSGI_APPLICATION","anchor":"wsgi-application","children":[]},{"title":"YEAR_MONTH_FORMAT","anchor":"year-month-format","children":[]},{"title":"X_FRAME_OPTIONS","anchor":"x-frame-options","children":[]}]},{"title":"认证","anchor":"auth","children":[{"title":"AUTHENTICATION_BACKENDS","anchor":"authentication-backends","children":[]},{"title":"AUTH_USER_MODEL","anchor":"auth-user-model","children":[]},{"title":"LOGIN_REDIRECT_URL","anchor":"login-redirect-url","children":[]},{"title":"LOGIN_URL","anchor":"login-url","children":[]},{"title":"LOGOUT_REDIRECT_URL","anchor":"logout-redirect-url","children":[]},{"title":"PASSWORD_RESET_TIMEOUT","anchor":"password-reset-timeout","children":[]},{"title":"PASSWORD_HASHERS","anchor":"password-hashers","children":[]},{"title":"AUTH_PASSWORD_VALIDATORS","anchor":"auth-password-validators","children":[]}]},{"title":"消息","anchor":"messages","children":[{"title":"MESSAGE_LEVEL","anchor":"message-level","children":[]},{"title":"MESSAGE_STORAGE","anchor":"message-storage","children":[]},{"title":"MESSAGE_TAGS","anchor":"message-tags","children":[]}]},{"title":"会话","anchor":"sessions","children":[{"title":"SESSION_CACHE_ALIAS","anchor":"session-cache-alias","children":[]},{"title":"SESSION_COOKIE_AGE","anchor":"session-cookie-age","children":[]},{"title":"SESSION_COOKIE_DOMAIN","anchor":"session-cookie-domain","children":[]},{"title":"SESSION_COOKIE_HTTPONLY","anchor":"session-cookie-httponly","children":[]},{"title":"SESSION_COOKIE_NAME","anchor":"session-cookie-name","children":[]},{"title":"SESSION_COOKIE_PATH","anchor":"session-cookie-path","children":[]},{"title":"SESSION_COOKIE_SAMESITE","anchor":"session-cookie-samesite","children":[]},{"title":"SESSION_COOKIE_SECURE","anchor":"session-cookie-secure","children":[]},{"title":"SESSION_ENGINE","anchor":"session-engine","children":[]},{"title":"SESSION_EXPIRE_AT_BROWSER_CLOSE","anchor":"session-expire-at-browser-close","children":[]},{"title":"SESSION_FILE_PATH","anchor":"session-file-path","children":[]},{"title":"SESSION_SAVE_EVERY_REQUEST","anchor":"session-save-every-request","children":[]},{"title":"SESSION_SERIALIZER","anchor":"session-serializer","children":[]}]},{"title":"站点","anchor":"sites","children":[{"title":"SITE_ID","anchor":"site-id","children":[]}]},{"title":"静态文件","anchor":"static-files","children":[{"title":"STATIC_ROOT","anchor":"static-root","children":[]},{"title":"STATIC_URL","anchor":"static-url","children":[]},{"title":"STATICFILES_DIRS","anchor":"staticfiles-dirs","children":[{"title":"前缀（可选）","anchor":"prefixes-optional","children":[]}]},{"title":"STATICFILES_FINDERS","anchor":"staticfiles-finders","children":[]}]},{"title":"核心配置专题索引","anchor":"core-settings-topical-index","children":[{"title":"缓存","anchor":"cache","children":[]},{"title":"数据库","anchor":"database","children":[]},{"title":"调试","anchor":"debugging","children":[]},{"title":"电子邮件","anchor":"email","children":[]},{"title":"发送错误","anchor":"error-reporting","children":[]},{"title":"文件上传","anchor":"file-uploads","children":[]},{"title":"表单","anchor":"forms","children":[]},{"title":"国际化（i18n ／ l10n）","anchor":"globalization-i18n-l10n","children":[{"title":"国际化（i18n）","anchor":"internationalization-i18n","children":[]},{"title":"本地化（l10n）","anchor":"localization-l10n","children":[]}]},{"title":"HTTP","anchor":"http","children":[]},{"title":"日志","anchor":"id14","children":[]},{"title":"模型","anchor":"models","children":[]},{"title":"安全","anchor":"security","children":[]},{"title":"序列化","anchor":"serialization","children":[]},{"title":"模板","anchor":"id15","children":[]},{"title":"测试中","anchor":"testing","children":[]},{"title":"URL","anchor":"urls","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API 参考","url":"/zh-hans/6.1/ref/"}],"prev":{"docname":"ref/schema-editor","title":"SchemaEditor","url":"/zh-hans/6.1/ref/schema-editor/"},"next":{"docname":"ref/signals","title":"信号","url":"/zh-hans/6.1/ref/signals/"},"formats":{"html":"/zh-hans/6.1/ref/settings/","markdown":"/zh-hans/6.1/ref/settings.md","json":"/zh-hans/6.1/ref/settings.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/ref/settings.txt","official":"https://docs.djangoproject.com/zh-hans/6.1/ref/settings/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}