{"title":"提交贡献","version":"6.0","locale":"zh-hans","docname":"internals/contributing/writing-code/submitting-patches","url":"/zh-hans/6.0/internals/contributing/writing-code/submitting-patches/","canonical":"https://djangodocs.dev/zh-hans/6.0/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<span id=\"trivial-change\"></span><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>See <a class=\"reference internal\" href=\"/zh-hans/6.0/internals/contributing/writing-code/working-with-git/\"><span class=\"doc\">使用 Git 和 GitHub 工作</span></a> for more\ndetails on how to use pull requests.</p>\n</section>\n<section id=\"claiming-tickets\">\n<span id=\"id1\"></span><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>因此，我们的政策是让贡献者“认领”工单，以便让其他开发人员知道某个特定的bug或功能正在处理中。</p>\n<p>如果您确定了要做出的贡献并且有能力解决（通过编程能力，Django内核知识水平和时间可用性来衡量），请按照以下步骤进行认领：</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference external\" href=\"https://code.djangoproject.com/github/login\">Log in using your GitHub account</a> or <a class=\"reference external\" href=\"https://www.djangoproject.com/accounts/register/\">create an account</a> in our ticket\nsystem. If you have an account but have forgotten your password, you can\nreset it using the <a class=\"reference external\" href=\"https://www.djangoproject.com/accounts/password/reset/\">password reset page</a>.</p></li>\n<li><p>If a ticket for this issue doesn't exist yet, create one in our\n<a class=\"reference external\" href=\"https://code.djangoproject.com/\">ticket tracker</a>. Remember that proposals for new features should follow\nthe <a class=\"reference internal\" href=\"/zh-hans/6.0/internals/contributing/bugs-and-features/#requesting-features\"><span class=\"std std-ref\">process for suggesting new features</span></a>.</p></li>\n<li><p>If a ticket for this issue already exists and has been accepted, make sure\nnobody else has claimed it. To do this, look at the &quot;Owned by&quot; section of\nthe ticket. If it's assigned to &quot;nobody,&quot; then it's available to be claimed.\nOtherwise, somebody else may be working on this ticket. Either find another\nbug/feature to work on, or contact the developer working on the ticket to\noffer your help. If a ticket has been assigned for weeks or months without\nany activity, it's probably safe to reassign it to yourself. If a ticket\nhasn't been approved yet, join the conversation.</p></li>\n<li><p>登录你的账户，如果还没有登录，点击工单页面左上角的“GitHub 登录”或“DjangoProject 登录”。登录后，你可以点击页面底部的“修改工单”按钮。</p></li>\n<li><p>点击“操作”部分中的“分配”单选按钮来认领工单。默认情况下，你的用户名将填入文本框。</p></li>\n<li><p>Finally, click the &quot;Submit changes&quot; button at the bottom to save.</p></li>\n</ul>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>If your change is not <a class=\"reference internal\" href=\"#trivial-change\"><span class=\"std std-ref\">trivial</span></a>, you have the option\nto sign and submit a <a class=\"reference external\" href=\"https://www.djangoproject.com/foundation/cla/\">Contributor License Agreement</a> clarifying the status\nof your contribution. This ensures that the Django Software Foundation has\nclear license to your contribution.</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>It is <em>always</em> acceptable, regardless of whether someone has claimed it or not,\nto link proposals to a ticket if you happen to have the changes ready.</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>The code required to fix a problem or add a feature is an essential part\nof a solution, but it is not the only part. A good fix should also include a\n<a class=\"reference internal\" href=\"/zh-hans/6.0/internals/contributing/writing-code/unit-tests/\"><span class=\"doc\">regression test</span></a> to\nvalidate the behavior that has been fixed and to prevent the problem from\narising again. Also, if some tickets are relevant to the code that you've\nwritten, mention the ticket numbers in some comments in the test so that one\ncan easily trace back the relevant discussions after your patch gets\ncommitted, and the tickets get closed.</p></li>\n<li><p>如果代码添加了新功能，或修改了现有功能的行为，更改还应包含文档。</p></li>\n</ul>\n<p>When you think your work is ready to be reviewed, send <a class=\"reference internal\" href=\"/zh-hans/6.0/internals/contributing/writing-code/working-with-git/\"><span class=\"doc\">a GitHub pull\nrequest</span></a>. If you can't\nsend a pull request for some reason, you can also use patches in Trac. When\nusing this style, follow these guidelines.</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-new-feature-ideas-tracker\">\n<h3>The new feature ideas tracker<a class=\"heading-anchor\" href=\"#the-new-feature-ideas-tracker\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you have an idea for a new feature, please create a new proposal (or join an\nexisting discussion) following the <a class=\"reference internal\" href=\"/zh-hans/6.0/internals/contributing/bugs-and-features/#requesting-features\"><span class=\"std std-ref\">process for suggesting new features</span></a>. You should explain the need for the change, go into\ndetails of the approach and discuss alternatives.</p>\n</section>\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 (that is not a new feature idea) on the\n<a class=\"reference external\" href=\"https://forum.djangoproject.com/\">Django Forum</a>. You should explain the need for the change, go into details of\nthe 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/6.0/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, the next step is to propose its inclusion by\nfollowing the <a class=\"reference internal\" href=\"/zh-hans/6.0/internals/contributing/bugs-and-features/#requesting-features\"><span class=\"std std-ref\">process for suggesting new features</span></a>.</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\nfollowing the <a class=\"reference internal\" href=\"/zh-hans/6.0/internals/contributing/bugs-and-features/#requesting-features\"><span class=\"std std-ref\">process for suggesting new features</span></a>.\nThis allows the community to provide feedback and helps refine the proposal.\nOnce the DEP is ready, the <a class=\"reference internal\" href=\"/zh-hans/6.0/internals/organization/#steering-council\"><span class=\"std std-ref\">Steering Council</span></a> votes on\nwhether 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=\"id2\"></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/6.0/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/6.0/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><span class=\"p\">,</span> <span class=\"n\">django_file_prefixes</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\">skip_file_prefixes</span><span class=\"o\">=</span><span class=\"n\">django_file_prefixes</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/6.0/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<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">django.utils.deprecation</span></code> module provides some helpful deprecation\nutilities, such as a <code class=\"docutils literal notranslate\"><span class=\"pre\">&#64;deprecate_posargs</span></code> decorator to assist with converting\npositional-or-keyword arguments to keyword-only. See the inline documentation\nin the module source.</p>\n</section>\n<section id=\"testing-with-a-django-project\">\n<h2>Testing with a Django project<a class=\"heading-anchor\" href=\"#testing-with-a-django-project\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>It's important to test local changes using a Django project. This allows\nensuring that the changes behave as expected in a real environment, especially\nfor user-facing features such as templates, forms, or the admin.</p>\n<p>To do this:</p>\n<ol class=\"arabic simple\">\n<li><p>Create a virtual environment and <a class=\"reference internal\" href=\"/zh-hans/6.0/intro/contributing/#intro-contributing-install-local-copy\"><span class=\"std std-ref\">install the cloned copy of Django in\neditable mode</span></a>.</p></li>\n<li><p>Set up a Django project outside the source tree (you can use the <a class=\"reference internal\" href=\"/zh-hans/6.0/intro/tutorial01/\"><span class=\"doc\">first\npart of the tutorial</span></a> for guidance).</p></li>\n</ol>\n<p>With this setup, any changes made to the Django checkout will take effect\nimmediately in the test project, allowing manual testing of contributions\nagainst a new or existing app.</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/6.0/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=\"id3\"></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>Use this checklist to review a pull request. If this contribution would not be\n<a class=\"reference internal\" href=\"#trivial-change\"><span class=\"std std-ref\">considered trivial</span></a>, first ensure it has an accepted\nticket before proceeding with the review.</p>\n<p>If the pull request passes all the criteria below and is not your own, please\nset the &quot;Triage Stage&quot; on the corresponding Trac ticket to &quot;Ready for checkin&quot;.\nIf you've left comments for improvement on the pull request, please tick the\nappropriate flags on the Trac ticket based on the results of your review:\n&quot;Patch needs improvement&quot;, &quot;Needs documentation&quot;, and/or &quot;Needs tests&quot;. As time\nand interest permit, mergers do final reviews of &quot;Ready for checkin&quot; tickets\nand will either commit the changes or bump it back to &quot;Accepted&quot; if further\nwork needs to be done.</p>\n<p>If you're looking to become a member of the <a class=\"reference external\" href=\"https://www.djangoproject.com/foundation/teams/#triage-review-team\">triage &amp; review team</a>, doing\nthorough reviews of contributions is a great way to earn trust.</p>\n<p>正在寻找要审查的补丁？查看 <a class=\"reference external\" href=\"https://dashboard.djangoproject.com/\">Django 开发仪表板</a> 的“需要审查的补丁”部分。</p>\n<p>希望你的拉取请求被审查？确保工单上的 Trac 标志已设置，以便工单出现在该队列中。</p>\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/6.0/internals/contributing/committing-code/#committing-guidelines\"><span class=\"std std-ref\">提交消息格式</span></a>？</p></li>\n<li><p>Are you the patch author and a new contributor? Please add yourself to the\n<a class=\"extlink-source reference external\" href=\"https://github.com/django/django/blob/stable/6.0.x/AUTHORS\">AUTHORS</a> file. At your option, submit a\n<a class=\"reference external\" href=\"https://www.djangoproject.com/foundation/cla/\">Contributor License Agreement</a>.</p></li>\n<li><p>Does this have an accepted ticket on Trac? All contributions require a ticket\nunless the <a class=\"reference internal\" href=\"#trivial-change\"><span class=\"std std-ref\">change is considered trivial</span></a>.</p></li>\n</ul>\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/6.0/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/6.0/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<li><p>If there is a <a class=\"reference internal\" href=\"/zh-hans/6.0/internals/contributing/writing-code/unit-tests/#code-coverage-on-pull-requests\"><span class=\"std std-ref\">code coverage report</span></a>\ncomment on the pull request, have you reviewed the missing coverage in\ncontext (considering database/platform-specific limitations)?</p></li>\n<li><p>If the change affects the Django admin or rendered HTML output, has\n<a class=\"reference internal\" href=\"/zh-hans/6.0/internals/contributing/accessibility/#accessibility-testing-baseline\"><span class=\"std std-ref\">accessibility testing</span></a> been done?</p></li>\n</ul>\n</section>\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/6.0/internals/contributing/writing-documentation/\"><span class=\"doc\">编写文档</span></a> 中的写作风格指南？</p></li>\n<li><p>是否存在任何 <a class=\"reference internal\" href=\"/zh-hans/6.0/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/6.0/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/6.0/internals/contributing/writing-documentation/#documenting-new-features\"><span class=\"std std-ref\">注释</span></a> ？</p></li>\n</ul>\n</section>\n<section id=\"id4\">\n<h3>弃用一个功能<a class=\"heading-anchor\" href=\"#id4\"><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>","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 new feature ideas tracker","anchor":"the-new-feature-ideas-tracker","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":"Testing with a Django project","anchor":"testing-with-a-django-project","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":"all-tickets","children":[]},{"title":"所有代码更改","anchor":"all-code-changes","children":[]},{"title":"文档","anchor":"documentation","children":[]},{"title":"错误","anchor":"bugs","children":[]},{"title":"新功能","anchor":"new-features","children":[]},{"title":"弃用一个功能","anchor":"id4","children":[]}]}],"breadcrumbs":[{"docname":"internals/index","title":"Django内部","url":"/zh-hans/6.0/internals/"},{"docname":"internals/contributing/index","title":"为 Django 做贡献","url":"/zh-hans/6.0/internals/contributing/"},{"docname":"internals/contributing/writing-code/index","title":"贡献代码","url":"/zh-hans/6.0/internals/contributing/writing-code/"}],"prev":{"docname":"internals/contributing/writing-code/index","title":"贡献代码","url":"/zh-hans/6.0/internals/contributing/writing-code/"},"next":{"docname":"internals/contributing/writing-code/unit-tests","title":"单元测试集","url":"/zh-hans/6.0/internals/contributing/writing-code/unit-tests/"},"formats":{"html":"/zh-hans/6.0/internals/contributing/writing-code/submitting-patches/","markdown":"/zh-hans/6.0/internals/contributing/writing-code/submitting-patches.md","json":"/zh-hans/6.0/internals/contributing/writing-code/submitting-patches.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/internals/contributing/writing-code/submitting-patches.txt","official":"https://docs.djangoproject.com/zh-hans/6.0/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","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}