{"title":"提交贡献","version":"5.1","locale":"zh-hans","docname":"internals/contributing/writing-code/submitting-patches","url":"/zh-hans/5.1/internals/contributing/writing-code/submitting-patches/","canonical":"https://djangodocs.dev/zh-hans/5.1/internals/contributing/writing-code/submitting-patches/","summary":"我们总是感激对 Django 代码的贡献。事实上，带有相关贡献的错误报告将比没有解决方案的错误报告修复得 快得多 。 错字修复和琐碎的文档更改 Link to this heading # 如果您正在修复一个非常微不足道的问题，例如更改文档中的一个单词，推荐的方法是使用 GitHub 提交拉取请求，而无需使用 Trac 工单。…","html":"<h1>提交贡献<a class=\"heading-anchor\" href=\"#submitting-contributions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>我们总是感激对 Django 代码的贡献。事实上，带有相关贡献的错误报告将比没有解决方案的错误报告修复得 <em>快得多</em>。</p>\n<section id=\"typo-fixes-and-trivial-documentation-changes\">\n<h2>错字修复和琐碎的文档更改<a class=\"heading-anchor\" href=\"#typo-fixes-and-trivial-documentation-changes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>如果您正在修复一个非常微不足道的问题，例如更改文档中的一个单词，推荐的方法是使用 GitHub 提交拉取请求，而无需使用 Trac 工单。</p>\n<p>有关如何使用拉取请求的更多详细信息，请参见 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-code/working-with-git/\"><span class=\"doc\">使用 Git 和 GitHub 工作</span></a> 。</p>\n</section>\n<section id=\"claiming-tickets\">\n<h2>“发布”工单<a class=\"heading-anchor\" href=\"#claiming-tickets\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>在一个全球有数百个贡献者的开源项目中，有效地管理沟通以避免重复工作并尽可能提高贡献者的效率是非常重要的。</p>\n<p>因此，我们的政策是供贡献者“发布”工单，以便让其他开发人员知道正在处理特定的错误或功能。</p>\n<p>如果您确定了要做出的贡献并且有能力解决（通过编程能力，Django内核知识水平和时间可用性来衡量），请按照以下步骤进行发表：</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference external\" href=\"https://www.djangoproject.com/accounts/register/\">使用您的 GitHub 帐户登录</a> 或在我们的工单系统中 <a class=\"reference external\" href=\"https://code.djangoproject.com/github/login\">创建一个帐户</a>。如果您有帐户但忘记了密码，可以使用 <a class=\"reference external\" href=\"https://www.djangoproject.com/accounts/password/reset/\">密码重置页面</a> 进行重置。</p></li>\n<li><p>如果尚无此问题的工单，请在我们的 <a class=\"reference external\" href=\"https://code.djangoproject.com/\">ticket tracker</a> 工单追踪系统中创建一个。</p></li>\n<li><p>如果此问题已有相关工单，请确保没有其他人认领。要做到这一点，查看工单的 &quot; Owned by &quot;（负责人）部分。如果它被分配给了 &quot; nobody &quot;（无人认领），那么它可以被认领。否则，可能已经有其他人正在处理此工单。您可以选择另一个错误或功能来处理，或者联系负责此工单的开发人员提供帮助。如果一个工单在数周或数月内没有任何活动，那么将其重新分配给自己可能是安全的。</p></li>\n<li><p>登录你的账户，如果还没有登录，点击工单页面左上角的“GitHub 登录”或“DjangoProject 登录”。登录后，你可以点击页面底部的“修改工单”按钮。</p></li>\n<li><p>点击“操作”部分中的“分配”单选按钮来认领工单。默认情况下，你的用户名将填入文本框。</p></li>\n<li><p>最后点击底部的“提交更改”按钮保存。</p></li>\n</ul>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>Django 软件基金会要求任何对 Django 做出非微小更改的贡献者签署并提交 <a class=\"reference external\" href=\"https://www.djangoproject.com/foundation/cla/\">贡献者许可协议</a>，这确保 Django 软件基金会对所有贡献拥有明确的许可，从而为所有用户提供明确的许可。</p>\n</aside>\n<section id=\"ticket-claimers-responsibility\">\n<h3>工单发表者的责任<a class=\"heading-anchor\" href=\"#ticket-claimers-responsibility\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>发布工单后，您有责任以合理及时的方式处理该工单。 如果您没有时间来处理它，请先取消发布或不发布它！</p>\n<p>如果一两周内没有任何关于特定已发布工单的进展迹象，则另一位开发人员可能会要求您放弃该发布了的工单，以使其不再被垄断，而其他人也可以发布。</p>\n<p>如果您已发布工单，并且要花很长时间（几天或几周）编写代码，请通过在工单上发布评论来使每个人都保持最新状态。如果您不提供定期更新，并且不响应进度报告的请求，则您对工单的要求可能会被撤消。</p>\n<p>与往常一样，多交流好过少交流！</p>\n</section>\n<section id=\"which-tickets-should-be-claimed\">\n<h3>应该发布哪类工单？<a class=\"heading-anchor\" href=\"#which-tickets-should-be-claimed\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>在某些情况下，执行认领工单的步骤可能过于繁琐。</p>\n<p>对于小更改，例如文档中的拼写错误或只需几分钟修复的小错误，你不需要经历认领工单的繁琐过程。直接提交你的更改即可完成！</p>\n<p>无论是否有人认领工单，如果你碰巧已经准备好更改，<em>总是</em> 可以接受将提案链接到工单。</p>\n</section>\n</section>\n<section id=\"contribution-style\">\n<span id=\"patch-style\"></span><h2>贡献风格<a class=\"heading-anchor\" href=\"#contribution-style\"><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>修复问题或添加功能所需的代码是解决方案的重要组成部分，但不是唯一的部分。一个好的修复还应包括一个 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-code/unit-tests/\"><span class=\"doc\">回归测试</span></a> 来验证已修复的行为并防止问题再次出现。此外，如果某些工单与你编写的代码相关，请在测试的注释中提及工单编号，以便在你的补丁提交后可以轻松追溯相关讨论，并且工单被关闭。</p></li>\n<li><p>如果代码添加了新功能，或修改了现有功能的行为，更改还应包含文档。</p></li>\n</ul>\n<p>当你认为你的工作已经准备好接受审查时，发送 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-code/working-with-git/\"><span class=\"doc\">GitHub 拉取请求</span></a>。如果由于某种原因无法发送拉取请求，你也可以在 Trac 中使用补丁。使用这种方式时，请遵循以下指南。</p>\n<ul class=\"simple\">\n<li><p>请以 <code class=\"docutils literal notranslate\"><span class=\"pre\">git</span> <span class=\"pre\">diff</span></code> 命令返回的格式提交补丁。</p></li>\n<li><p>使用“附加文件”按钮将补丁附加到 <a class=\"reference external\" href=\"https://code.djangoproject.com/\">ticket tracker</a> 工单跟踪系统中的工单上。 除非是单行补丁，否则请 <em>不要</em> 将补丁放入工单描述或注释中。</p></li>\n<li><p>用扩展名 <code class=\"docutils literal notranslate\"><span class=\"pre\">.diff</span></code> 命名补丁文件； 这将使工单跟踪系统应用正确的语法突出显示，这非常有帮助。</p></li>\n</ul>\n<p>无论您以何种方式提交工作成果，请按照以下步骤操作。</p>\n<ul class=\"simple\">\n<li><p>确保你的代码满足我们的 <a class=\"reference internal\" href=\"#patch-review-checklist\"><span class=\"std std-ref\">贡献清单</span></a> 中的要求。</p></li>\n<li><p>勾选工单上的 &quot;Has patch&quot; 复选框，并确保 &quot;Needs documentation&quot;、&quot;Needs tests&quot; 和 &quot;Patch needs improvement&quot; 复选框没有被勾选。这将使工单显示在 <a class=\"reference external\" href=\"https://dashboard.djangoproject.com/\">Development dashboard</a> 的 &quot;Patches needing review&quot; 队列中。</p></li>\n</ul>\n</section>\n<section id=\"contributions-which-require-community-feedback\">\n<h2>需要社区反馈的贡献<a class=\"heading-anchor\" href=\"#contributions-which-require-community-feedback\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>当补丁引入新的 Django 功能并做出某种设计决策时，需要更广泛的社区讨论。如果方法涉及 <a class=\"reference internal\" href=\"#deprecating-a-feature\"><span class=\"std std-ref\">弃用</span></a> 或引入破坏性更改，这一点尤为重要。</p>\n<p>以下是获得社区反馈的不同方法。</p>\n<section id=\"the-django-forum\">\n<h3>The Django Forum<a class=\"heading-anchor\" href=\"#the-django-forum\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You can propose a change on the <a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a>. You should explain the need\nfor the change, go into details of the approach and discuss alternatives.</p>\n<p>请在贡献中包含此类讨论的链接。</p>\n</section>\n<section id=\"third-party-package\">\n<h3>第三方包<a class=\"heading-anchor\" href=\"#third-party-package\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django 不接受实验性功能。所有功能必须遵循我们的 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/release-process/#internal-release-deprecation-policy\"><span class=\"std std-ref\">弃用政策</span></a>。因此，Django 可能需要数月或数年的时间来迭代 API 设计。</p>\n<p>如果你需要用户对公共接口的反馈，最好先创建一个第三方包。你可以更快地迭代公共 API，同时验证功能的需求。</p>\n<p>Once this package becomes stable and there are clear benefits of incorporating\naspects into Django core, starting a discussion on the <a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a> would be\nthe next step.</p>\n</section>\n<section id=\"django-enhancement-proposal-dep\">\n<h3>Django 增强提案 (DEP)<a class=\"heading-anchor\" href=\"#django-enhancement-proposal-dep\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>类似于 Python 的 PEP，Django 有 <a class=\"reference external\" href=\"https://github.com/django/deps\">Django 增强提案</a> 或 DEP。DEP 是一份设计文档，向 Django 社区提供信息，或描述 Django 的新功能或流程。它们提供了功能的技术规范及其理由。DEP 也是提议和收集社区对主要新功能意见的主要机制。</p>\n<p>Before considering writing a DEP, it is recommended to first open a discussion\non the <a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a>. This allows the community to provide feedback and helps\nrefine the proposal. Once the DEP is ready the <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/organization/#steering-council\"><span class=\"std std-ref\">Steering Council</span></a> votes on whether to accept it.</p>\n<p>一些已被批准并完全实施的 DEP 示例：</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference external\" href=\"https://github.com/django/deps/blob/main/final/0181-orm-expressions.rst\">DEP 181: ORM 表达式</a></p></li>\n<li><p><a class=\"reference external\" href=\"https://github.com/django/deps/blob/main/final/0182-multiple-template-engines.rst\">DEP 182: 多模板引擎</a></p></li>\n<li><p><a class=\"reference external\" href=\"https://github.com/django/deps/blob/main/final/0201-simplified-routing-syntax.rst\">DEP 201: 简化路由语法</a></p></li>\n</ul>\n</section>\n</section>\n<section id=\"deprecating-a-feature\">\n<span id=\"id1\"></span><h2>弃用一个功能<a class=\"heading-anchor\" href=\"#deprecating-a-feature\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django 中的代码可能被弃用的原因有几个：</p>\n<ul class=\"simple\">\n<li><p>如果一个功能在与向后兼容性不兼容的方式下进行了改进或修改，旧的功能或行为将被弃用。</p></li>\n<li><p>有时，Django 会包含一个 Python 库的后移版本，而该库在 Django 当前支持的 Python 版本中不包含。当 Django 不再需要支持不包含该库的旧版本 Python 时，该库将在 Django 中被弃用。</p></li>\n</ul>\n<p>正如 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/release-process/#internal-release-deprecation-policy\"><span class=\"std std-ref\">弃用政策</span></a> 所描述的那样，第一个弃用某项功能的 Django 版本（<code class=\"docutils literal notranslate\"><span class=\"pre\">A.B</span></code>）在调用被弃用功能时应该引发一个 <code class=\"docutils literal notranslate\"><span class=\"pre\">RemovedInDjangoXXWarning</span></code> 警告（其中 XX 是将要删除该功能的 Django 版本）。假设我们有良好的测试覆盖率，在启用警告的情况下，这些警告将在 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-code/unit-tests/#running-unit-tests\"><span class=\"std std-ref\">运行测试套件</span></a> 时转换为错误：<code class=\"docutils literal notranslate\"><span class=\"pre\">python</span> <span class=\"pre\">-Wa</span> <span class=\"pre\">runtests.py</span></code>。因此，在添加 <code class=\"docutils literal notranslate\"><span class=\"pre\">RemovedInDjangoXXWarning</span></code> 时，您需要消除或消除运行测试时生成的任何警告。</p>\n<p>第一步是通过 Django 自身去除对被弃用行为的使用。接下来，您可以使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">ignore_warnings</span></code> 装饰器来消除测试中实际测试被弃用行为的警告，可以在测试或类级别使用它：</p>\n<ol class=\"arabic\">\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=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.test</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">ignore_warnings</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.utils.deprecation</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">RemovedInDjangoXXWarning</span>\n\n\n<span class=\"nd\">@ignore_warnings</span><span class=\"p\">(</span><span class=\"n\">category</span><span class=\"o\">=</span><span class=\"n\">RemovedInDjangoXXWarning</span><span class=\"p\">)</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">test_foo</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span> <span class=\"o\">...</span>\n</code></pre></div>\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=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.test</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">ignore_warnings</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.utils.deprecation</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">RemovedInDjangoXXWarning</span>\n\n\n<span class=\"nd\">@ignore_warnings</span><span class=\"p\">(</span><span class=\"n\">category</span><span class=\"o\">=</span><span class=\"n\">RemovedInDjangoXXWarning</span><span class=\"p\">)</span>\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">MyDeprecatedTests</span><span class=\"p\">(</span><span class=\"n\">unittest</span><span class=\"o\">.</span><span class=\"n\">TestCase</span><span class=\"p\">):</span> <span class=\"o\">...</span>\n</code></pre></div>\n</li>\n</ol>\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.deprecation</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">RemovedInDjangoXXWarning</span>\n\n\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">test_foo_deprecation_warning</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n    <span class=\"n\">msg</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;Expected deprecation message&quot;</span>\n    <span class=\"k\">with</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">assertWarnsMessage</span><span class=\"p\">(</span><span class=\"n\">RemovedInDjangoXXWarning</span><span class=\"p\">,</span> <span class=\"n\">msg</span><span class=\"p\">)</span> <span class=\"k\">as</span> <span class=\"n\">ctx</span><span class=\"p\">:</span>\n        <span class=\"c1\"># invoke deprecated behavior</span>\n        <span class=\"o\">...</span>\n    <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">assertEqual</span><span class=\"p\">(</span><span class=\"n\">ctx</span><span class=\"o\">.</span><span class=\"n\">filename</span><span class=\"p\">,</span> <span class=\"vm\">__file__</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>重要的是在没有警告引用但在弃用结束时需要更改或删除的代码上方包含一个 <code class=\"docutils literal notranslate\"><span class=\"pre\">RemovedInDjangoXXWarning</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\">import</span><span class=\"w\"> </span><span class=\"nn\">warnings</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.utils.deprecation</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">RemovedInDjangoXXWarning</span>\n\n\n<span class=\"c1\"># RemovedInDjangoXXWarning.</span>\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">old_private_helper</span><span class=\"p\">():</span>\n    <span class=\"c1\"># Helper function that is only used in foo().</span>\n    <span class=\"k\">pass</span>\n\n\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">foo</span><span class=\"p\">():</span>\n    <span class=\"n\">warnings</span><span class=\"o\">.</span><span class=\"n\">warn</span><span class=\"p\">(</span>\n        <span class=\"s2\">&quot;foo() is deprecated.&quot;</span><span class=\"p\">,</span>\n        <span class=\"n\">category</span><span class=\"o\">=</span><span class=\"n\">RemovedInDjangoXXWarning</span><span class=\"p\">,</span>\n        <span class=\"n\">stacklevel</span><span class=\"o\">=</span><span class=\"mi\">2</span><span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n    <span class=\"n\">old_private_helper</span><span class=\"p\">()</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>最后，还有一些更新需要进行，以更新 Django 的文档：</p>\n<ol class=\"arabic simple\">\n<li><p>如果现有功能已经在文档中记录，请使用 <code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">deprecated::</span> <span class=\"pre\">A.B</span></code> 注解在文档中标记它为已弃用。如果适用，包括一个简短的描述和有关升级路径的说明。</p></li>\n<li><p>将已弃用行为的描述以及升级路径（如果适用）添加到当前版本的发行说明（<code class=\"docutils literal notranslate\"><span class=\"pre\">docs/releases/A.B.txt</span></code>）中，放在 &quot;Features deprecated in A.B&quot; 标题下。</p></li>\n<li><p>在适当的版本下，将一个条目添加到弃用时间表（<code class=\"docutils literal notranslate\"><span class=\"pre\">docs/internals/deprecation.txt</span></code>）中，描述将要被移除的代码。</p></li>\n</ol>\n<p>一旦完成了这些步骤，你就完成了弃用过程。在每个 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/release-process/#term-Feature-release\"><span class=\"xref std std-term\">特性发布</span></a> 中，与新版本匹配的所有 <code class=\"docutils literal notranslate\"><span class=\"pre\">RemovedInDjangoXXWarning</span></code> 都会被移除。</p>\n</section>\n<section id=\"javascript-contributions\">\n<h2>JavaScript 贡献<a class=\"heading-anchor\" href=\"#javascript-contributions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>有关 JavaScript 贡献的信息，请参阅 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-code/javascript/#javascript-patches\"><span class=\"std std-ref\">JavaScript 补丁</span></a> 文档。</p>\n</section>\n<section id=\"optimization-patches\">\n<h2>优化补丁<a class=\"heading-anchor\" href=\"#optimization-patches\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>旨在提供性能改进的补丁应提供基准测试，显示补丁前后的影响，并分享供审查者复现的命令。</p>\n<section id=\"django-asv-benchmarks\">\n<span id=\"id2\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">django-asv</span></code> 基准测试<a class=\"heading-anchor\" href=\"#django-asv-benchmarks\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><a class=\"reference external\" href=\"https://github.com/django/django-asv/\">django-asv</a> 监控 Django 代码的性能随时间的变化。这些基准测试可以通过在拉取请求上标记 <code class=\"docutils literal notranslate\"><span class=\"pre\">benchmark</span></code> 来运行。强烈鼓励添加这些基准测试。</p>\n</section>\n</section>\n<section id=\"contribution-checklist\">\n<span id=\"patch-review-checklist\"></span><h2>贡献清单<a class=\"heading-anchor\" href=\"#contribution-checklist\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>使用此清单审查拉取请求。如果你正在审查不是你自己提交的拉取请求，并且它满足以下所有标准，请将相应的 Trac 工单的“分类阶段”设置为“准备检入”。如果你在拉取请求上留下了改进意见，请根据审查结果在 Trac 工单上勾选适当的标志：“补丁需要改进”、“需要文档”和/或“需要测试”。根据时间和兴趣，合并者会对“准备检入”的工单进行最终审查，并提交更改，或者如果需要进一步工作，则将其退回“已接受”。如果你想成为合并者，彻底审查贡献是赢得信任的好方法。</p>\n<p>正在寻找要审查的补丁？查看 <a class=\"reference external\" href=\"https://dashboard.djangoproject.com/\">Django 开发仪表板</a> 的“需要审查的补丁”部分。</p>\n<p>希望你的拉取请求被审查？确保工单上的 Trac 标志已设置，以便工单出现在该队列中。</p>\n<section id=\"documentation\">\n<h3>文档<a class=\"heading-anchor\" href=\"#documentation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p>文档是否能够在没有任何错误的情况下构建（从 <code class=\"docutils literal notranslate\"><span class=\"pre\">docs</span></code> 目录执行 <code class=\"docutils literal notranslate\"><span class=\"pre\">make</span> <span class=\"pre\">html</span></code>，或者在 Windows 上执行 <code class=\"docutils literal notranslate\"><span class=\"pre\">make.bat</span> <span class=\"pre\">html</span></code>）？</p></li>\n<li><p>文档是否遵循 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-documentation/\"><span class=\"doc\">编写文档</span></a> 中的写作风格指南？</p></li>\n<li><p>是否存在任何 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-documentation/#documentation-spelling-check\"><span class=\"std std-ref\">拼写错误</span></a>？</p></li>\n</ul>\n</section>\n<section id=\"bugs\">\n<h3>错误<a class=\"heading-anchor\" href=\"#bugs\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p>是否有适当的回归测试（在应用修复之前，测试应该失败）？</p></li>\n<li><p>如果是一个符合 Django 稳定版本的 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/release-process/#supported-versions-policy\"><span class=\"std std-ref\">可回退</span></a> 的 bug，是否在 <code class=\"docutils literal notranslate\"><span class=\"pre\">docs/releases/A.B.C.txt</span></code> 中有一份发行说明？只会应用到主分支的 bug 修复不需要发行说明。</p></li>\n</ul>\n</section>\n<section id=\"new-features\">\n<h3>新功能<a class=\"heading-anchor\" href=\"#new-features\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p>是否有测试来 &quot;运行&quot; 所有新代码？</p></li>\n<li><p>是否在 <code class=\"docutils literal notranslate\"><span class=\"pre\">docs/releases/A.B.txt</span></code> 中有一份发行说明？</p></li>\n<li><p>是否为该功能提供了文档，并且文档是否适当地使用了 <code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">versionadded::</span> <span class=\"pre\">A.B</span></code> 或 <code class=\"docutils literal notranslate\"><span class=\"pre\">..</span> <span class=\"pre\">versionchanged::</span> <span class=\"pre\">A.B</span></code> 进行了 <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-documentation/#documenting-new-features\"><span class=\"std std-ref\">注释</span></a> ？</p></li>\n</ul>\n</section>\n<section id=\"id3\">\n<h3>弃用一个功能<a class=\"heading-anchor\" href=\"#id3\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>请参阅 <a class=\"reference internal\" href=\"#deprecating-a-feature\"><span class=\"std std-ref\">弃用一个功能</span></a> 指南。</p>\n</section>\n<section id=\"all-code-changes\">\n<h3>所有代码更改<a class=\"heading-anchor\" href=\"#all-code-changes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p>Does the <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-code/coding-style/\"><span class=\"doc\">coding style</span></a> conform to our\nguidelines? Are there any  <code class=\"docutils literal notranslate\"><span class=\"pre\">black</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">blacken-docs</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">flake8</span></code>,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">isort</span></code>, or <code class=\"docutils literal notranslate\"><span class=\"pre\">zizmor</span></code> errors? You can install the <a class=\"reference internal\" href=\"/zh-hans/5.1/internals/contributing/writing-code/coding-style/#coding-style-pre-commit\"><span class=\"std std-ref\">pre-commit</span></a> hooks to automatically catch these errors.</p></li>\n<li><p>如果更改在任何方面不向后兼容，是否在发行说明（<code class=\"docutils literal notranslate\"><span class=\"pre\">docs/releases/A.B.txt</span></code>）中有说明？</p></li>\n<li><p>Django 的测试套件是否通过？</p></li>\n</ul>\n</section>\n<section id=\"all-tickets\">\n<h3>所有工单<a class=\"heading-anchor\" href=\"#all-tickets\"><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=\"/zh-hans/5.1/internals/contributing/committing-code/#committing-guidelines\"><span class=\"std std-ref\">提交消息格式</span></a>？</p></li>\n<li><p>您是否是补丁的作者并且是新的贡献者？请将自己添加到 <a class=\"extlink-source reference external\" href=\"https://github.com/django/django/blob/stable/5.1.x/AUTHORS\">AUTHORS</a> 文件并提交 <a class=\"reference external\" href=\"https://www.djangoproject.com/foundation/cla/\">Contributor License Agreement</a>。</p></li>\n</ul>\n</section>\n</section>","rootId":"submitting-contributions","toc":[{"title":"错字修复和琐碎的文档更改","anchor":"typo-fixes-and-trivial-documentation-changes","children":[]},{"title":"“发布”工单","anchor":"claiming-tickets","children":[{"title":"工单发表者的责任","anchor":"ticket-claimers-responsibility","children":[]},{"title":"应该发布哪类工单？","anchor":"which-tickets-should-be-claimed","children":[]}]},{"title":"贡献风格","anchor":"contribution-style","children":[]},{"title":"需要社区反馈的贡献","anchor":"contributions-which-require-community-feedback","children":[{"title":"The Django Forum","anchor":"the-django-forum","children":[]},{"title":"第三方包","anchor":"third-party-package","children":[]},{"title":"Django 增强提案 (DEP)","anchor":"django-enhancement-proposal-dep","children":[]}]},{"title":"弃用一个功能","anchor":"deprecating-a-feature","children":[]},{"title":"JavaScript 贡献","anchor":"javascript-contributions","children":[]},{"title":"优化补丁","anchor":"optimization-patches","children":[{"title":"django-asv 基准测试","anchor":"django-asv-benchmarks","children":[]}]},{"title":"贡献清单","anchor":"contribution-checklist","children":[{"title":"文档","anchor":"documentation","children":[]},{"title":"错误","anchor":"bugs","children":[]},{"title":"新功能","anchor":"new-features","children":[]},{"title":"弃用一个功能","anchor":"id3","children":[]},{"title":"所有代码更改","anchor":"all-code-changes","children":[]},{"title":"所有工单","anchor":"all-tickets","children":[]}]}],"breadcrumbs":[{"docname":"internals/index","title":"Django内部","url":"/zh-hans/5.1/internals/"},{"docname":"internals/contributing/index","title":"为 Django 做贡献","url":"/zh-hans/5.1/internals/contributing/"},{"docname":"internals/contributing/writing-code/index","title":"贡献代码","url":"/zh-hans/5.1/internals/contributing/writing-code/"}],"prev":{"docname":"internals/contributing/writing-code/index","title":"贡献代码","url":"/zh-hans/5.1/internals/contributing/writing-code/"},"next":{"docname":"internals/contributing/writing-code/unit-tests","title":"单元测试集","url":"/zh-hans/5.1/internals/contributing/writing-code/unit-tests/"},"formats":{"html":"/zh-hans/5.1/internals/contributing/writing-code/submitting-patches/","markdown":"/zh-hans/5.1/internals/contributing/writing-code/submitting-patches.md","json":"/zh-hans/5.1/internals/contributing/writing-code/submitting-patches.json"},"source":"https://github.com/django/django/blob/stable/5.1.x/docs/internals/contributing/writing-code/submitting-patches.txt","official":"https://docs.djangoproject.com/zh-hans/5.1/internals/contributing/writing-code/submitting-patches/","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","it","pt-br","ko","es","el","pl"]}