{"title":"编写文档","version":"3.1","locale":"zh-hans","docname":"internals/contributing/writing-documentation","url":"/zh-hans/3.1/internals/contributing/writing-documentation/","canonical":"https://djangodocs.dev/zh-hans/3.1/internals/contributing/writing-documentation/","summary":"我们极其重视文档的一致性和可读性。毕竟，Django 是在需要快速发布新闻的环境下开发的！所以，我们像对待我们的代码一样对待我们的文档：我们期望尽可能频繁地更新它。 一般来说，文档会在以下两种情况时更新： 一般改进：通过更清晰的书写和更多示例，更正、修复文档错误，更好的解释功能。…","html":"<h1>编写文档<a class=\"heading-anchor\" href=\"#writing-documentation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>我们极其重视文档的一致性和可读性。毕竟，Django 是在需要快速发布新闻的环境下开发的！所以，我们像对待我们的代码一样对待我们的文档：我们期望尽可能频繁地更新它。</p>\n<p>一般来说，文档会在以下两种情况时更新：</p>\n<ul class=\"simple\">\n<li><p>一般改进：通过更清晰的书写和更多示例，更正、修复文档错误，更好的解释功能。</p></li>\n<li><p>新特性：自上一个版本发布后，添加到框架中的功能文档。</p></li>\n</ul>\n<p>本节介绍文档作者如何以最有用和最不容易出错的方式修改文档。</p>\n<section id=\"getting-the-raw-documentation\">\n<h2>获得原始文档<a class=\"heading-anchor\" href=\"#getting-the-raw-documentation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django 文档可在 <a class=\"reference external\" href=\"https://docs.djangoproject.com/\">https://docs.djangoproject.com/</a> 以网页的形式阅读，但我们以一种更灵活的方式编辑它——一系列的文本文件。这些文件位于  Django 的每个发布分支的顶级目录 <code class=\"docutils literal notranslate\"><span class=\"pre\">docs/</span></code> 下。</p>\n<p>如果你想修改文档，请先从源码仓库获取开发版的 Django （参见 <span class=\"xref std std-ref\">安装开发版</span>）。开发版拥有最新最好的文档，就像它拥有最新最好的代码一样。我们也会在最新发布分支上提交针对文档的修复和优化（取决于提交者）。这是因为让最新版本的文档保持最新和正确是非常有利的（参见 <span class=\"xref std std-ref\">不同版本文档间的区别</span>）。</p>\n</section>\n<section id=\"getting-started-with-sphinx\">\n<h2>开始使用 Sphinx<a class=\"heading-anchor\" href=\"#getting-started-with-sphinx\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django  的文档使用 <a class=\"reference external\" href=\"https://www.sphinx-doc.org/\">Sphinx</a> 文档系统——基于 <a class=\"reference external\" href=\"https://docutils.sourceforge.io/\">docutils</a>。基本思想是将轻量格式话的纯文本转化为 HTML，PDF 或其它任意输出格式。</p>\n<p>To build the documentation locally, install Sphinx:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-0-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code><span class=\"gp\">$ </span>python<span class=\"w\"> </span>-m<span class=\"w\"> </span>pip<span class=\"w\"> </span>install<span class=\"w\"> </span>Sphinx\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-0-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py -m pip install Sphinx\n</code></pre></div></div></div>\n<p>Then from the <code class=\"docutils literal notranslate\"><span class=\"pre\">docs</span></code> directory, build the HTML:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-1-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code><span class=\"gp\">$ </span>make<span class=\"w\"> </span>html\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-1-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> make.bat html\n</code></pre></div></div></div>\n<p>编写文档前，你需要阅读 <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html#rst-index\" title=\"(in Sphinx v9.1.1)\"><span class=\"xref std std-ref\">reStructuredText 指引</span></a>。</p>\n<p>本地构建的文档的主题会和 <a class=\"reference external\" href=\"https://docs.djangoproject.com\">docs.djangoproject.com</a> 上的不同。没事！如果你修改后的文档在本地看起来没啥问题，那么在网站上也会没问题。</p>\n</section>\n<section id=\"how-the-documentation-is-organized\">\n<h2>文档是如何组成<a class=\"heading-anchor\" href=\"#how-the-documentation-is-organized\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>文档被分为以下几个类别：</p>\n<ul>\n<li><p><a class=\"reference internal\" href=\"/zh-hans/3.1/intro/\"><span class=\"doc\">教程</span></a> 通过几步手把手的教学帮助读者创建一个小玩意。</p>\n<p>教程的目的是帮助读者尽可能早地实现一些有用的东西，以便给他们带来信心。</p>\n<p>Explain the nature of the problem we're solving, so that the reader\nunderstands what we're trying to achieve. Don't feel that you need to begin\nwith explanations of how things work - what matters is what the reader does,\nnot what you explain. It can be helpful to refer back to what you've done and\nexplain afterwards.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"/zh-hans/3.1/topics/\"><span class=\"doc\">主题指引</span></a> 旨在在一个较高的层次介绍一个原则或主题。</p>\n<p>链接至参考资料而不要重复它。使用示例时，不要不情愿解释对您而言非常基本的事物——它对别人而言可能需要解释。</p>\n<p>提供背景信息有助于新人将主题和他们已知的东西联系起来。</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"/zh-hans/3.1/ref/\"><span class=\"doc\">Reference guides</span></a> contain technical reference for APIs.\nThey describe the functioning of Django's internal machinery and instruct in\nits use.</p>\n<p>Keep reference material tightly focused on the subject. Assume that the\nreader already understands the basic concepts involved but needs to know or\nbe reminded of how Django does it.</p>\n<p>Reference guides aren't the place for general explanation. If you find\nyourself explaining basic concepts, you may want to move that material to a\ntopic guide.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"/zh-hans/3.1/howto/\"><span class=\"doc\">How-to guides</span></a> are recipes that take the reader through\nsteps in key subjects.</p>\n<p>What matters most in a how-to guide is what a user wants to achieve.\nA how-to should always be result-oriented rather than focused on internal\ndetails of how Django implements whatever is being discussed.</p>\n<p>These guides are more advanced than tutorials and assume some knowledge about\nhow Django works. Assume that the reader has followed the tutorials and don't\nhesitate to refer the reader back to the appropriate tutorial rather than\nrepeat the same material.</p>\n</li>\n</ul>\n</section>\n<section id=\"writing-style\">\n<h2>书写格式<a class=\"heading-anchor\" href=\"#writing-style\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When using pronouns in reference to a hypothetical person, such as &quot;a user with\na session cookie&quot;, gender neutral pronouns (they/their/them) should be used.\nInstead of:</p>\n<ul class=\"simple\">\n<li><p>他或她……使用他们。</p></li>\n<li><p>him 或 her... 使用 them。</p></li>\n<li><p>他的或她的……使用他们的。</p></li>\n<li><p>his 或 hers... 使用 theirs。</p></li>\n<li><p>himself 或 herself... 使用 themselves。</p></li>\n</ul>\n<p>Try to avoid using words that minimize the difficulty involved in a task or\noperation, such as &quot;easily&quot;, &quot;simply&quot;, &quot;just&quot;, &quot;merely&quot;, &quot;straightforward&quot;, and\nso on. People's experience may not match your expectations, and they may become\nfrustrated when they do not find a step as &quot;straightforward&quot; or &quot;simple&quot; as it\nis implied to be.</p>\n</section>\n<section id=\"commonly-used-terms\">\n<h2>常用术语<a class=\"heading-anchor\" href=\"#commonly-used-terms\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>以下是整个文档中常用术语的一些格式指南：</p>\n<ul class=\"simple\">\n<li><p><strong>Django</strong> -- 当提及该框架时，大写Django。它仅在Python代码中和djangoproject.com徽标中使用小写字母。</p></li>\n<li><p><strong>email</strong> -- 无连字符。</p></li>\n<li><p><strong>MySQL</strong>, <strong>PostgreSQL</strong>, <strong>SQLite</strong></p></li>\n<li><p><strong>SQL</strong> -- 当提及SQL时，预期的发音应该是“Ess Queue Ell”而不是“sequel”。因此，在诸如“Returns an SQL expression”之类的短语中，“SQL”前应该使用“an”而不是“a”。</p></li>\n<li><p><strong>Python</strong> -- 当提及该语言时大写。</p></li>\n<li><p><strong>realize</strong>, <strong>customize</strong>, <strong>initialize</strong>, etc. -- 使用美式的“ize”后缀，而不是“ise”。</p></li>\n<li><p><strong>subclass</strong> -- 它是一个没有连字符的单个单词，既作为动词（“子类模型”）又作为名词（“创建子类”）。</p></li>\n<li><p><strong>Web</strong>, <strong>World Wide Web</strong>, <strong>the Web</strong> -- 指万维网时注意Web总是大写。</p></li>\n<li><p><strong>website</strong> -- 用一个单词表示，不大写。</p></li>\n</ul>\n</section>\n<section id=\"django-specific-terminology\">\n<h2>Django专用术语<a class=\"heading-anchor\" href=\"#django-specific-terminology\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<ul class=\"simple\">\n<li><p><strong>model (模型)</strong> -- 它不是大写的。</p></li>\n<li><p><strong>template</strong> -- 它不是大写的。</p></li>\n<li><p><strong>URLconf</strong> -- 使用了三个大写字母，在“conf”之前没有空格。</p></li>\n<li><p><strong>view</strong> -- 它不是大写的。</p></li>\n</ul>\n</section>\n<section id=\"guidelines-for-restructuredtext-files\">\n<h2>reStructuredText 文件语法指南<a class=\"heading-anchor\" href=\"#guidelines-for-restructuredtext-files\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>这些准则规定了我们的reST（reStructuredText）文档格式：</p>\n<ul>\n<li><p>在部分标题中，仅将首字母和专有名词大写。</p></li>\n<li><p>将文档以80个字符宽包装，除非将代码示例分成两行或出于其他充分理由而使可读性大大降低。</p></li>\n<li><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>Add ``django.contrib.auth`` to your ``INSTALLED_APPS``...\n</code></pre></div>\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>Add :mod:`django.contrib.auth` to your :setting:`INSTALLED_APPS`...\n</code></pre></div>\n<p>This is because Sphinx will generate proper links for the latter, which\ngreatly helps readers.</p>\n<p>You can prefix the target with a <code class=\"docutils literal notranslate\"><span class=\"pre\">~</span></code> (that's a tilde) to get only the\n&quot;last bit&quot; of that path. So <code class=\"docutils literal notranslate\"><span class=\"pre\">:mod:`~django.contrib.auth`</span></code> will\ndisplay a link with the title &quot;auth&quot;.</p>\n</li>\n<li><p>使用 <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#module-sphinx.ext.intersphinx\" title=\"(in Sphinx v9.1.1)\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">intersphinx</span></code></a> 来引用Python和Sphinx的文档。</p></li>\n<li><p>Add <code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">code-block::</span> <span class=\"pre\">&lt;lang&gt;</span></code> to literal blocks so that they get\nhighlighted. Prefer relying on automatic highlighting using <code class=\"docutils literal notranslate\"><span class=\"pre\">::</span></code>\n(two colons). This has the benefit that if the code contains some invalid\nsyntax, it won't be highlighted. Adding <code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">code-block::</span> <span class=\"pre\">python</span></code>, for\nexample, will force highlighting despite invalid syntax.</p></li>\n<li><p>To improve readability, use <code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">admonition::</span> <span class=\"pre\">Descriptive</span> <span class=\"pre\">title</span></code> rather than\n<code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">note::</span></code>. Use these boxes sparingly.</p></li>\n<li><p>Use these heading styles:</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=\"o\">===</span>\n<span class=\"n\">One</span>\n<span class=\"o\">===</span>\n\n<span class=\"n\">Two</span>\n<span class=\"o\">===</span>\n\n<span class=\"n\">Three</span>\n<span class=\"o\">-----</span>\n\n<span class=\"n\">Four</span>\n<span class=\"o\">~~~~</span>\n\n<span class=\"n\">Five</span>\n<span class=\"o\">^^^^</span>\n</code></pre></div>\n</li>\n<li><p>Use <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-rfc\" title=\"(in Sphinx v9.1.1)\"><code class=\"xref rst rst-role docutils literal notranslate\"><span class=\"pre\">:rfc:</span></code></a> to reference RFC and try to link to the relevant\nsection if possible. For example, use <code class=\"docutils literal notranslate\"><span class=\"pre\">:rfc:`2324#section-2.3.2`</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">:rfc:`Custom</span> <span class=\"pre\">link</span> <span class=\"pre\">text</span> <span class=\"pre\">&lt;2324#section-2.3.2&gt;`</span></code>.</p></li>\n<li><p>Use <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-pep\" title=\"(in Sphinx v9.1.1)\"><code class=\"xref rst rst-role docutils literal notranslate\"><span class=\"pre\">:pep:</span></code></a> to reference a Python Enhancement Proposal (PEP)\nand try to link to the relevant section if possible. For example, use\n<code class=\"docutils literal notranslate\"><span class=\"pre\">:pep:`20#easter-egg`</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">:pep:`Easter</span> <span class=\"pre\">Egg</span> <span class=\"pre\">&lt;20#easter-egg&gt;`</span></code>.</p></li>\n<li><p>Use <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-mimetype\" title=\"(in Sphinx v9.1.1)\"><code class=\"xref rst rst-role docutils literal notranslate\"><span class=\"pre\">:mimetype:</span></code></a> to refer to a MIME Type unless the value\nis quoted for a code example.</p></li>\n<li><p>Use <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/referencing.html#role-envvar\" title=\"(in Sphinx v9.1.1)\"><code class=\"xref rst rst-role docutils literal notranslate\"><span class=\"pre\">:envvar:</span></code></a> to refer to an environment variable. You may\nalso need to define a reference to the documentation for that environment\nvariable using <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/domains/standard.html#directive-envvar\" title=\"(in Sphinx v9.1.1)\"><code class=\"xref rst rst-dir docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">envvar::</span></code></a>.</p></li>\n</ul>\n</section>\n<section id=\"django-specific-markup\">\n<h2>Django特定的标记<a class=\"heading-anchor\" href=\"#django-specific-markup\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Besides <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html#rst-index\" title=\"(in Sphinx v9.1.1)\"><span class=\"xref std std-ref\">Sphinx's built-in markup</span></a>, Django's docs\ndefine some extra description units:</p>\n<ul>\n<li><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=\"o\">..</span> <span class=\"n\">setting</span><span class=\"p\">::</span> <span class=\"n\">INSTALLED_APPS</span>\n</code></pre></div>\n<p>为了连接配置，请使用配置 <code class=\"docutils literal notranslate\"><span class=\"pre\">:setting:`INSTALLED_APPS`</span></code>。</p>\n</li>\n<li><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=\"o\">..</span> <span class=\"n\">templatetag</span><span class=\"p\">::</span> <span class=\"n\">regroup</span>\n</code></pre></div>\n<p>为了链接，请使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">:ttag:`regroup`</span></code>。</p>\n</li>\n<li><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=\"o\">..</span> <span class=\"n\">templatefilter</span><span class=\"p\">::</span> <span class=\"n\">linebreaksbr</span>\n</code></pre></div>\n<p>为了链接，请使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">:tfilter:`linebreaksbr`</span></code> 。</p>\n</li>\n<li><p>字段查询（例如 <code class=\"docutils literal notranslate\"><span class=\"pre\">Foo.objects.filter(bar__exact=whatever)</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=\"o\">..</span> <span class=\"n\">fieldlookup</span><span class=\"p\">::</span> <span class=\"n\">exact</span>\n</code></pre></div>\n<p>为了链接，请使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">:lookup:`exact`</span></code>。</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</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=\"o\">..</span> <span class=\"n\">django</span><span class=\"o\">-</span><span class=\"n\">admin</span><span class=\"p\">::</span> <span class=\"n\">migrate</span>\n</code></pre></div>\n<p>To link, use <code class=\"docutils literal notranslate\"><span class=\"pre\">:djadmin:`migrate`</span></code>.</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</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=\"o\">..</span> <span class=\"n\">django</span><span class=\"o\">-</span><span class=\"n\">admin</span><span class=\"o\">-</span><span class=\"n\">option</span><span class=\"p\">::</span> <span class=\"o\">--</span><span class=\"n\">traceback</span>\n</code></pre></div>\n<p>To link, use <code class=\"docutils literal notranslate\"><span class=\"pre\">:option:`command_name</span> <span class=\"pre\">--traceback`</span></code> (or omit <code class=\"docutils literal notranslate\"><span class=\"pre\">command_name</span></code>\nfor the options shared by all commands like <code class=\"docutils literal notranslate\"><span class=\"pre\">--verbosity</span></code>).</p>\n</li>\n<li><p>Links to Trac tickets (typically reserved for patch release notes):</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>:ticket:`12345`\n</code></pre></div>\n</li>\n</ul>\n<p>Django's documentation uses a custom <code class=\"docutils literal notranslate\"><span class=\"pre\">console</span></code> directive for documenting\ncommand-line examples involving <code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">python</span></code>,\netc.). In the HTML documentation, it renders a two-tab UI, with one tab showing\na Unix-style command prompt and a second tab showing a Windows prompt.</p>\n<p>For example, you can replace this fragment:</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>use this command:\n\n.. code-block:: console\n\n    $ python manage.py shell\n</code></pre></div>\n<p>with this one:</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>use this command:\n\n.. console::\n\n    $ python manage.py shell\n</code></pre></div>\n<p>Notice two things:</p>\n<ul class=\"simple\">\n<li><p>You usually will replace occurrences of the <code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">code-block::</span> <span class=\"pre\">console</span></code>\ndirective.</p></li>\n<li><p>You don't need to change the actual content of the code example. You still\nwrite it assuming a Unix-y environment (i.e. a <code class=\"docutils literal notranslate\"><span class=\"pre\">'$'</span></code> prompt symbol,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'/'</span></code> as filesystem path components separator, etc.)</p></li>\n</ul>\n<p>The example above will render a code example block with two tabs. The first\none will show:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code><span class=\"gp\">$ </span>python<span class=\"w\"> </span>manage.py<span class=\"w\"> </span>shell\n</code></pre></div>\n<p>(No changes from what <code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">code-block::</span> <span class=\"pre\">console</span></code> would have rendered).</p>\n<p>The second one will show:</p>\n<div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows code\"><code><span class=\"gp\">...\\&gt;</span> py manage.py shell\n</code></pre></div>\n</section>\n<section id=\"documenting-new-features\">\n<span id=\"id3\"></span><h2>记录新功能<a class=\"heading-anchor\" href=\"#documenting-new-features\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>我们对新功能的政策是：</p>\n<blockquote>\n<div><p>所有新功能的文档都应以明确指定仅在Django开发版本中可用的功能的方式编写。 假设文档读者正在使用最新版本，而不是开发版本。</p>\n</div></blockquote>\n<p>Our preferred way for marking new features is by prefacing the features'\ndocumentation with: &quot;<code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">versionadded::</span> <span class=\"pre\">X.Y</span></code>&quot;, followed by a mandatory\nblank line and an optional description (indented).</p>\n<p>常规改进或应强调的其他API更改应使用 &quot;<code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">versionchanged::</span> <span class=\"pre\">X.Y</span></code>&quot; 指令（与上述 <code class=\"docutils literal notranslate\"><span class=\"pre\">versionadded</span></code> 相同。</p>\n<p>These <code class=\"docutils literal notranslate\"><span class=\"pre\">versionadded</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">versionchanged</span></code> blocks should be &quot;self-contained.&quot;\nIn other words, since we only keep these annotations around for two releases,\nit's nice to be able to remove the annotation and its contents without having\nto reflow, reindent, or edit the surrounding text. For example, instead of\nputting the entire description of a new or changed feature in a block, do\nsomething like this:</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>.. class:: Author(first_name, last_name, middle_name=None)\n\n    A person who writes books.\n\n    ``first_name`` is ...\n\n    ...\n\n    ``middle_name`` is ...\n\n    .. versionchanged:: A.B\n\n        The ``middle_name`` argument was added.\n</code></pre></div>\n<p>Put the changed annotation notes at the bottom of a section, not the top.</p>\n<p>Also, avoid referring to a specific version of Django outside a\n<code class=\"docutils literal notranslate\"><span class=\"pre\">versionadded</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">versionchanged</span></code> block. Even inside a block, it's often\nredundant to do so as these annotations render as &quot;New in Django A.B:&quot; and\n&quot;Changed in Django A.B&quot;, respectively.</p>\n<p>If a function, attribute, etc. is added, it's also okay to use a\n<code class=\"docutils literal notranslate\"><span class=\"pre\">versionadded</span></code> annotation like this:</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=\"o\">..</span> <span class=\"n\">attribute</span><span class=\"p\">::</span> <span class=\"n\">Author</span><span class=\"o\">.</span><span class=\"n\">middle_name</span>\n\n    <span class=\"o\">..</span> <span class=\"n\">versionadded</span><span class=\"p\">::</span> <span class=\"n\">A</span><span class=\"o\">.</span><span class=\"n\">B</span>\n\n    <span class=\"n\">An</span> <span class=\"n\">author</span><span class=\"s1\">&#39;s middle name.</span>\n</code></pre></div>\n<p>We can remove the <code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">versionadded::</span> <span class=\"pre\">A.B</span></code> annotation without any indentation\nchanges when the time comes.</p>\n</section>\n<section id=\"minimizing-images\">\n<h2>Minimizing images<a class=\"heading-anchor\" href=\"#minimizing-images\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Optimize image compression where possible. For PNG files, use OptiPNG and\nAdvanceCOMP's <code class=\"docutils literal notranslate\"><span class=\"pre\">advpng</span></code>:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code><span class=\"gp\">$ </span><span class=\"nb\">cd</span><span class=\"w\"> </span>docs\n<span class=\"gp\">$ </span>optipng<span class=\"w\"> </span>-o7<span class=\"w\"> </span>-zm1-9<span class=\"w\"> </span>-i0<span class=\"w\"> </span>-strip<span class=\"w\"> </span>all<span class=\"w\"> </span><span class=\"sb\">`</span>find<span class=\"w\"> </span>.<span class=\"w\"> </span>-type<span class=\"w\"> </span>f<span class=\"w\"> </span>-not<span class=\"w\"> </span>-path<span class=\"w\"> </span><span class=\"s2\">&quot;./_build/*&quot;</span><span class=\"w\"> </span>-name<span class=\"w\"> </span><span class=\"s2\">&quot;*.png&quot;</span><span class=\"sb\">`</span>\n<span class=\"gp\">$ </span>advpng<span class=\"w\"> </span>-z4<span class=\"w\"> </span><span class=\"sb\">`</span>find<span class=\"w\"> </span>.<span class=\"w\"> </span>-type<span class=\"w\"> </span>f<span class=\"w\"> </span>-not<span class=\"w\"> </span>-path<span class=\"w\"> </span><span class=\"s2\">&quot;./_build/*&quot;</span><span class=\"w\"> </span>-name<span class=\"w\"> </span><span class=\"s2\">&quot;*.png&quot;</span><span class=\"sb\">`</span>\n</code></pre></div>\n<p>This is based on OptiPNG version 0.7.5. Older versions may complain about the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">--strip</span> <span class=\"pre\">all</span></code> option being lossy.</p>\n</section>\n<section id=\"an-example\">\n<h2>一个例子<a class=\"heading-anchor\" href=\"#an-example\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>有关如何将它们组合在一起的快速示例，请考虑以下假设示例：</p>\n<ul>\n<li><p>首先， <code class=\"docutils literal notranslate\"><span class=\"pre\">ref/settings.txt</span></code> 配置文件可能具有如下总体布局：</p>\n<div class=\"code-block\" data-language=\"rst\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Rst</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=\"Rst code\"><code><span class=\"gh\">========</span>\n<span class=\"gh\">Settings</span>\n<span class=\"gh\">========</span>\n\n<span class=\"c\">...</span>\n\n<span class=\"p\">..</span> <span class=\"nt\">_available-settings:</span>\n\n<span class=\"gh\">Available settings</span>\n<span class=\"gh\">==================</span>\n\n<span class=\"c\">...</span>\n\n<span class=\"p\">..</span> <span class=\"nt\">_deprecated-settings:</span>\n\n<span class=\"gh\">Deprecated settings</span>\n<span class=\"gh\">===================</span>\n\n<span class=\"c\">...</span>\n</code></pre></div>\n</li>\n<li><p>接下来， <code class=\"docutils literal notranslate\"><span class=\"pre\">topics/settings.txt</span></code> 配置文档可能包含以下内容：</p>\n<div class=\"code-block\" data-language=\"rst\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Rst</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=\"Rst code\"><code>You can access a :ref:`listing of all available settings\n<span class=\"nt\">&lt;available-settings&gt;</span>`. For a list of deprecated settings see\n<span class=\"na\">:ref:</span><span class=\"nv\">`deprecated-settings`</span>.\n\nYou can find both in the :doc:`settings reference document\n<span class=\"nt\">&lt;/ref/settings&gt;</span>`.\n</code></pre></div>\n<p>当我们想链接到另一个文档时，我们使用 <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/referencing.html#role-doc\" title=\"(in Sphinx v9.1.1)\"><code class=\"xref rst rst-role docutils literal notranslate\"><span class=\"pre\">doc</span></code></a> 交叉引用元素；当我们想链接到文档中的任意的位置时，请使用 <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/referencing.html#role-ref\" title=\"(in Sphinx v9.1.1)\"><code class=\"xref rst rst-role docutils literal notranslate\"><span class=\"pre\">ref</span></code></a> 元素。</p>\n</li>\n<li><p>接下来，请注意配置的注释方式：</p>\n<div class=\"code-block\" data-language=\"rst\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Rst</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=\"Rst code\"><code><span class=\"p\">..</span> <span class=\"ow\">setting</span><span class=\"p\">::</span> ADMINS\n\n<span class=\"gh\">ADMINS</span>\n<span class=\"gh\">======</span>\n\nDefault: <span class=\"s\">``[]``</span> (Empty list)\n\nA list of all the people who get code error notifications. When\n<span class=\"s\">``DEBUG=False``</span> and a view raises an exception, Django will email these people\nwith the full exception information. Each member of the list should be a tuple\nof (Full name, email address). Example<span class=\"se\">::</span>\n\n<span class=\"s\">    [(&#39;John&#39;, &#39;john@example.com&#39;), (&#39;Mary&#39;, &#39;mary@example.com&#39;)]</span>\n\nNote that Django will email <span class=\"ge\">*all*</span> of these people whenever an error happens.\nSee <span class=\"na\">:doc:</span><span class=\"nv\">`/howto/error-reporting`</span> for more information.\n</code></pre></div>\n<p>This marks up the following header as the &quot;canonical&quot; target for the\nsetting <code class=\"docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code>. This means any time I talk about <code class=\"docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code>,\nI can reference it using <code class=\"docutils literal notranslate\"><span class=\"pre\">:setting:`ADMINS`</span></code>.</p>\n</li>\n</ul>\n<p>基本上，这就是所有东西融合在一起的方式。</p>\n</section>\n<section id=\"spelling-check\">\n<span id=\"documentation-spelling-check\"></span><h2>拼写检查<a class=\"heading-anchor\" href=\"#spelling-check\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Before you commit your docs, it's a good idea to run the spelling checker.\nYou'll need to install <a class=\"reference external\" href=\"https://pypi.org/project/sphinxcontrib-spelling/\">sphinxcontrib-spelling</a> first. Then from the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">docs</span></code> directory, run <code class=\"docutils literal notranslate\"><span class=\"pre\">make</span> <span class=\"pre\">spelling</span></code>. Wrong words (if any) along with the\nfile and line number where they occur will be saved to\n<code class=\"docutils literal notranslate\"><span class=\"pre\">_build/spelling/output.txt</span></code>.</p>\n<p>If you encounter false-positives (error output that actually is correct), do\none of the following:</p>\n<ul class=\"simple\">\n<li><p>Surround inline code or brand/technology names with grave accents (`).</p></li>\n<li><p>查找拼写检查程序发现的同义词。</p></li>\n<li><p>如果，只是如果，你确定你的单词拼写是正确的——将其加入 <code class=\"docutils literal notranslate\"><span class=\"pre\">docs/spelling_wordlist</span></code> （请保持这个列表以字母顺序排列）。</p></li>\n</ul>\n</section>\n<section id=\"translating-documentation\">\n<h2>翻译文档<a class=\"heading-anchor\" href=\"#translating-documentation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>查看 <a class=\"reference internal\" href=\"/zh-hans/3.1/internals/contributing/localizing/#translating-documentation\"><span class=\"std std-ref\">本地化 Django 文档</span></a>，如果你想帮助我们将文档翻译成其它语言。</p>\n</section>\n<section id=\"django-admin-man-page\">\n<span id=\"django-admin-manpage\"></span><h2><code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</span></code> 手册页面<a class=\"heading-anchor\" href=\"#django-admin-man-page\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Sphinx can generate a manual page for the\n<a class=\"reference internal\" href=\"/zh-hans/3.1/ref/django-admin/\"><span class=\"doc\">django-admin</span></a> command. This is configured in\n<code class=\"docutils literal notranslate\"><span class=\"pre\">docs/conf.py</span></code>. Unlike other documentation output, this man page should be\nincluded in the Django repository and the releases as\n<code class=\"docutils literal notranslate\"><span class=\"pre\">docs/man/django-admin.1</span></code>. There isn't a need to update this file when\nupdating the documentation, as it's updated once as part of the release process.</p>\n<p>To generate an updated version of the man page, run <code class=\"docutils literal notranslate\"><span class=\"pre\">make</span> <span class=\"pre\">man</span></code> in the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">docs</span></code> directory. The new man page will be written in\n<code class=\"docutils literal notranslate\"><span class=\"pre\">docs/_build/man/django-admin.1</span></code>.</p>\n</section>","rootId":"writing-documentation","toc":[{"title":"获得原始文档","anchor":"getting-the-raw-documentation","children":[]},{"title":"开始使用 Sphinx","anchor":"getting-started-with-sphinx","children":[]},{"title":"文档是如何组成","anchor":"how-the-documentation-is-organized","children":[]},{"title":"书写格式","anchor":"writing-style","children":[]},{"title":"常用术语","anchor":"commonly-used-terms","children":[]},{"title":"Django专用术语","anchor":"django-specific-terminology","children":[]},{"title":"reStructuredText 文件语法指南","anchor":"guidelines-for-restructuredtext-files","children":[]},{"title":"Django特定的标记","anchor":"django-specific-markup","children":[]},{"title":"记录新功能","anchor":"documenting-new-features","children":[]},{"title":"Minimizing images","anchor":"minimizing-images","children":[]},{"title":"一个例子","anchor":"an-example","children":[]},{"title":"拼写检查","anchor":"spelling-check","children":[]},{"title":"翻译文档","anchor":"translating-documentation","children":[]},{"title":"django-admin 手册页面","anchor":"django-admin-man-page","children":[]}],"breadcrumbs":[{"docname":"internals/index","title":"Django internals","url":"/zh-hans/3.1/internals/"},{"docname":"internals/contributing/index","title":"为 Django 做贡献","url":"/zh-hans/3.1/internals/contributing/"}],"prev":{"docname":"internals/contributing/writing-code/javascript","title":"JavaScript","url":"/zh-hans/3.1/internals/contributing/writing-code/javascript/"},"next":{"docname":"internals/contributing/localizing","title":"使 Django 本地化","url":"/zh-hans/3.1/internals/contributing/localizing/"},"formats":{"html":"/zh-hans/3.1/internals/contributing/writing-documentation/","markdown":"/zh-hans/3.1/internals/contributing/writing-documentation.md","json":"/zh-hans/3.1/internals/contributing/writing-documentation.json"},"source":"https://github.com/django/django/blob/stable/3.1.x/docs/internals/contributing/writing-documentation.txt","official":"https://docs.djangoproject.com/zh-hans/3.1/internals/contributing/writing-documentation/","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","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}