{"title":"Writing your first patch for Django","version":"1.8","locale":"en","docname":"intro/contributing","url":"/en/1.8/intro/contributing/","canonical":"https://djangodocs.dev/en/1.8/intro/contributing/","summary":"Interested in giving back to the community a little? Maybe you’ve found a bug in Django that you’d like to see fixed, or maybe there’s a small feature you…","html":"<h1>Writing your first patch for Django<a class=\"heading-anchor\" href=\"#writing-your-first-patch-for-django\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"introduction\">\n<h2>Introduction<a class=\"heading-anchor\" href=\"#introduction\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Interested in giving back to the community a little? Maybe you’ve found a bug\nin Django that you’d like to see fixed, or maybe there’s a small feature you\nwant added.</p>\n<p>Contributing back to Django itself is the best way to see your own concerns\naddressed. This may seem daunting at first, but it’s really pretty simple.\nWe’ll walk you through the entire process, so you can learn by example.</p>\n<section id=\"who-s-this-tutorial-for\">\n<h3>Who’s this tutorial for?<a class=\"heading-anchor\" href=\"#who-s-this-tutorial-for\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>For this tutorial, we expect that you have at least a basic understanding of\nhow Django works. This means you should be comfortable going through the\nexisting tutorials on <a class=\"reference internal\" href=\"/en/1.8/intro/tutorial01/\"><span class=\"doc\">writing your first Django app</span></a>.\nIn addition, you should have a good understanding of Python itself. But if you\ndon’t, <a class=\"reference external\" href=\"http://www.diveintopython3.net/\">Dive Into Python</a> is a fantastic (and free) online book for\nbeginning Python programmers.</p>\n<p>Those of you who are unfamiliar with version control systems and Trac will find\nthat this tutorial and its links include just enough information to get started.\nHowever, you’ll probably want to read some more about these different tools if\nyou plan on contributing to Django regularly.</p>\n<p>For the most part though, this tutorial tries to explain as much as possible,\nso that it can be of use to the widest audience.</p>\n<aside class=\"admonition-where-to-get-help admonition\" role=\"note\">\n<p class=\"admonition-title\">Where to get help:</p>\n<p>If you’re having trouble going through this tutorial, please post a message\nto <a class=\"reference internal\" href=\"/en/1.8/internals/mailing-lists/#django-developers-mailing-list\"><span class=\"std std-ref\">django-developers</span></a> or drop by <a class=\"reference external\" href=\"irc://irc.freenode.net/django-dev\">#django-dev on irc.freenode.net</a> to\nchat with other Django users who might be able to help.</p>\n</aside>\n</section>\n<section id=\"what-does-this-tutorial-cover\">\n<h3>What does this tutorial cover?<a class=\"heading-anchor\" href=\"#what-does-this-tutorial-cover\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>We’ll be walking you through contributing a patch to Django for the first time.\nBy the end of this tutorial, you should have a basic understanding of both the\ntools and the processes involved. Specifically, we’ll be covering the following:</p>\n<ul class=\"simple\">\n<li><p>Installing Git.</p></li>\n<li><p>How to download a development copy of Django.</p></li>\n<li><p>Running Django’s test suite.</p></li>\n<li><p>Writing a test for your patch.</p></li>\n<li><p>Writing the code for your patch.</p></li>\n<li><p>Testing your patch.</p></li>\n<li><p>Generating a patch file for your changes.</p></li>\n<li><p>Where to look for more information.</p></li>\n</ul>\n<p>Once you’re done with the tutorial, you can look through the rest of\n<a class=\"reference internal\" href=\"/en/1.8/internals/contributing/\"><span class=\"doc\">Django’s documentation on contributing</span></a>.\nIt contains lots of great information and is a must read for anyone who’d like\nto become a regular contributor to Django. If you’ve got questions, it’s\nprobably got the answers.</p>\n</section>\n</section>\n<section id=\"installing-git\">\n<h2>Installing Git<a class=\"heading-anchor\" href=\"#installing-git\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>For this tutorial, you’ll need Git installed to download the current\ndevelopment version of Django and to generate patch files for the changes you\nmake.</p>\n<p>To check whether or not you have Git installed, enter <code class=\"docutils literal notranslate\">git</code> into the command\nline. If you get messages saying that this command could not be found, you’ll have\nto download and install it, see <a class=\"reference external\" href=\"http://git-scm.com/download\">Git’s download page</a>.</p>\n<p>If you’re not that familiar with Git, you can always find out more about its\ncommands (once it’s installed) by typing <code class=\"docutils literal notranslate\">git help</code> into the command line.</p>\n</section>\n<section id=\"getting-a-copy-of-django-s-development-version\">\n<h2>Getting a copy of Django’s development version<a class=\"heading-anchor\" href=\"#getting-a-copy-of-django-s-development-version\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The first step to contributing to Django is to get a copy of the source code.\nFrom the command line, use the <code class=\"docutils literal notranslate\">cd</code> command to navigate to the directory\nwhere you’ll want your local copy of Django to live.</p>\n<p>Download the Django source code repository using the following command:</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>git clone https<span class=\"p\">:</span><span class=\"o\">//</span>github<span class=\"o\">.</span>com<span class=\"o\">/</span>django<span class=\"o\">/</span>django<span class=\"o\">.</span>git\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>For users who wish to use <a class=\"reference external\" href=\"http://www.virtualenv.org\">virtualenv</a>, you can use:</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>pip install <span class=\"o\">-</span>e <span class=\"o\">/</span>path<span class=\"o\">/</span>to<span class=\"o\">/</span>your<span class=\"o\">/</span>local<span class=\"o\">/</span>clone<span class=\"o\">/</span>django<span class=\"o\">/</span>\n</code></pre></div>\n<p>(where <code class=\"docutils literal notranslate\">django</code> is the directory of your clone that contains\n<code class=\"docutils literal notranslate\">setup.py</code>) to link your cloned checkout into a virtual environment. This\nis a great option to isolate your development copy of Django from the rest\nof your system and avoids potential package conflicts.</p>\n</aside>\n</section>\n<section id=\"rolling-back-to-a-previous-revision-of-django\">\n<h2>Rolling back to a previous revision of Django<a class=\"heading-anchor\" href=\"#rolling-back-to-a-previous-revision-of-django\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>For this tutorial, we’ll be using ticket <a class=\"extlink-ticket reference external\" href=\"https://code.djangoproject.com/ticket/17549\">#17549</a> as a case study, so we’ll\nrewind Django’s version history in git to before that ticket’s patch was\napplied. This will allow us to go through all of the steps involved in writing\nthat patch from scratch, including running Django’s test suite.</p>\n<p><strong>Keep in mind that while we’ll be using an older revision of Django’s trunk\nfor the purposes of the tutorial below, you should always use the current\ndevelopment revision of Django when working on your own patch for a ticket!</strong></p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>The patch for this ticket was written by Ulrich Petri, and it was applied\nto Django as <a class=\"reference external\" href=\"https://github.com/django/django/commit/ac2052ebc84c45709ab5f0f25e685bf656ce79bc\">commit ac2052ebc84c45709ab5f0f25e685bf656ce79bc</a>.\nConsequently, we’ll be using the revision of Django just prior to that,\n<a class=\"reference external\" href=\"https://github.com/django/django/commit/39f5bc7fc3a4bb43ed8a1358b17fe0521a1a63ac\">commit 39f5bc7fc3a4bb43ed8a1358b17fe0521a1a63ac</a>.</p>\n</aside>\n<p>Navigate into Django’s root directory (that’s the one that contains <code class=\"docutils literal notranslate\">django</code>,\n<code class=\"docutils literal notranslate\">docs</code>, <code class=\"docutils literal notranslate\">tests</code>, <code class=\"docutils literal notranslate\">AUTHORS</code>, etc.). You can then check out the older\nrevision of Django that we’ll be using in the tutorial below:</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>git checkout <span class=\"mi\">39</span>f5bc7fc3a4bb43ed8a1358b17fe0521a1a63ac\n</code></pre></div>\n</section>\n<section id=\"running-django-s-test-suite-for-the-first-time\">\n<h2>Running Django’s test suite for the first time<a class=\"heading-anchor\" href=\"#running-django-s-test-suite-for-the-first-time\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When contributing to Django it’s very important that your code changes don’t\nintroduce bugs into other areas of Django.  One way to check that Django still\nworks after you make your changes is by running Django’s test suite. If all\nthe tests still pass, then you can be reasonably sure that your changes\nhaven’t completely broken Django. If you’ve never run Django’s test suite\nbefore, it’s a good idea to run it once beforehand just to get familiar with\nwhat its output is supposed to look like.</p>\n<p>We can run the test suite by simply <code class=\"docutils literal notranslate\">cd</code>-ing into the Django <code class=\"docutils literal notranslate\">tests/</code>\ndirectory and, if you’re using GNU/Linux, Mac OS X or some other flavor of\nUnix, run:</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>PYTHONPATH<span class=\"o\">=..</span> python runtests<span class=\"o\">.</span>py <span class=\"o\">--</span>settings<span class=\"o\">=</span>test_sqlite\n</code></pre></div>\n<p>If you’re on Windows, the above should work provided that you are using\n“Git Bash” provided by the default Git install. GitHub has a <a class=\"reference external\" href=\"https://help.github.com/articles/set-up-git#platform-windows\">nice tutorial</a>.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>If you’re using <code class=\"docutils literal notranslate\">virtualenv</code>, you can omit <code class=\"docutils literal notranslate\">PYTHONPATH=..</code> when running\nthe tests. This instructs Python to look for Django in the parent directory\nof <code class=\"docutils literal notranslate\">tests</code>. <code class=\"docutils literal notranslate\">virtualenv</code> puts your copy of Django on the <code class=\"docutils literal notranslate\">PYTHONPATH</code>\nautomatically.</p>\n</aside>\n<p>Now sit back and relax. Django’s entire test suite has over 4800 different\ntests, so it can take anywhere from 5 to 15 minutes to run, depending on the\nspeed of your computer.</p>\n<p>While Django’s test suite is running, you’ll see a stream of characters\nrepresenting the status of each test as it’s run. <code class=\"docutils literal notranslate\">E</code> indicates that an error\nwas raised during a test, and <code class=\"docutils literal notranslate\">F</code> indicates that a test’s assertions failed.\nBoth of these are considered to be test failures. Meanwhile, <code class=\"docutils literal notranslate\">x</code> and <code class=\"docutils literal notranslate\">s</code>\nindicated expected failures and skipped tests, respectively. Dots indicate\npassing tests.</p>\n<p>Skipped tests are typically due to missing external libraries required to run\nthe test; see <a class=\"reference internal\" href=\"/en/1.8/internals/contributing/writing-code/unit-tests/#running-unit-tests-dependencies\"><span class=\"std std-ref\">Running all the tests</span></a> for a list of dependencies\nand be sure to install any for tests related to the changes you are making (we\nwon’t need any for this tutorial).</p>\n<p>Once the tests complete, you should be greeted with a message informing you\nwhether the test suite passed or failed. Since you haven’t yet made any changes\nto Django’s code, the entire test suite <strong>should</strong> pass. If you get failures or\nerrors make sure you’ve followed all of the previous steps properly. See\n<a class=\"reference internal\" href=\"/en/1.8/internals/contributing/writing-code/unit-tests/#running-unit-tests\"><span class=\"std std-ref\">Running the unit tests</span></a> for more information.</p>\n<p>Note that the latest Django trunk may not always be stable. When developing\nagainst trunk, you can check <a class=\"reference external\" href=\"http://djangoci.com\">Django’s continuous integration builds</a> to\ndetermine if the failures are specific to your machine or if they are also\npresent in Django’s official builds. If you click to view a particular build,\nyou can view the “Configuration Matrix” which shows failures broken down by\nPython version and database backend.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>For this tutorial and the ticket we’re working on, testing against SQLite\nis sufficient, however, it’s possible (and sometimes necessary) to\n<a class=\"reference internal\" href=\"/en/1.8/internals/contributing/writing-code/unit-tests/#running-unit-tests-settings\"><span class=\"std std-ref\">run the tests using a different database</span></a>.</p>\n</aside>\n</section>\n<section id=\"writing-some-tests-for-your-ticket\">\n<h2>Writing some tests for your ticket<a class=\"heading-anchor\" href=\"#writing-some-tests-for-your-ticket\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>In most cases, for a patch to be accepted into Django it has to include tests.\nFor bug fix patches, this means writing a regression test to ensure that the\nbug is never reintroduced into Django later on. A regression test should be\nwritten in such a way that it will fail while the bug still exists and pass\nonce the bug has been fixed. For patches containing new features, you’ll need\nto include tests which ensure that the new features are working correctly.\nThey too should fail when the new feature is not present, and then pass once it\nhas been implemented.</p>\n<p>A good way to do this is to write your new tests first, before making any\nchanges to the code. This style of development is called\n<a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Test-driven_development\">test-driven development</a> and can be applied to both entire projects and\nsingle patches. After writing your tests, you then run them to make sure that\nthey do indeed fail (since you haven’t fixed that bug or added that feature\nyet). If your new tests don’t fail, you’ll need to fix them so that they do.\nAfter all, a regression test that passes regardless of whether a bug is present\nis not very helpful at preventing that bug from reoccurring down the road.</p>\n<p>Now for our hands-on example.</p>\n<section id=\"writing-some-tests-for-ticket-17549\">\n<h3>Writing some tests for ticket #17549<a class=\"heading-anchor\" href=\"#writing-some-tests-for-ticket-17549\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Ticket <a class=\"extlink-ticket reference external\" href=\"https://code.djangoproject.com/ticket/17549\">#17549</a> describes the following, small feature addition:</p>\n<blockquote>\n<div><p>It’s useful for URLField to give you a way to open the URL; otherwise you\nmight as well use a CharField.</p>\n</div></blockquote>\n<p>In order to resolve this ticket, we’ll add a <code class=\"docutils literal notranslate\">render</code> method to the\n<code class=\"docutils literal notranslate\">AdminURLFieldWidget</code> in order to display a clickable link above the input\nwidget. Before we make those changes though, we’re going to write a couple\ntests to verify that our modification functions correctly and continues to\nfunction correctly in the future.</p>\n<p>Navigate to Django’s <code class=\"docutils literal notranslate\">tests/regressiontests/admin_widgets/</code> folder and\nopen the <code class=\"docutils literal notranslate\">tests.py</code> file. Add the following code on line 269 right before the\n<code class=\"docutils literal notranslate\">AdminFileWidgetTest</code> class:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span> <span class=\"nc\">AdminURLWidgetTest</span><span class=\"p\">(</span>DjangoTestCase<span class=\"p\">):</span>\n    <span class=\"k\">def</span> <span class=\"nf\">test_render</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        w <span class=\"o\">=</span> widgets<span class=\"o\">.</span>AdminURLFieldWidget<span class=\"p\">()</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertHTMLEqual<span class=\"p\">(</span>\n            conditional_escape<span class=\"p\">(</span>w<span class=\"o\">.</span>render<span class=\"p\">(</span><span class=\"s1\">&#39;test&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;&#39;</span><span class=\"p\">)),</span>\n            <span class=\"s1\">&#39;&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; /&gt;&#39;</span>\n        <span class=\"p\">)</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertHTMLEqual<span class=\"p\">(</span>\n            conditional_escape<span class=\"p\">(</span>w<span class=\"o\">.</span>render<span class=\"p\">(</span><span class=\"s1\">&#39;test&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;http://example.com&#39;</span><span class=\"p\">)),</span>\n            <span class=\"s1\">&#39;&lt;p class=&quot;url&quot;&gt;Currently:&lt;a href=&quot;http://example.com&quot;&gt;http://example.com&lt;/a&gt;&lt;br /&gt;Change:&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; value=&quot;http://example.com&quot; /&gt;&lt;/p&gt;&#39;</span>\n        <span class=\"p\">)</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">test_render_idn</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        w <span class=\"o\">=</span> widgets<span class=\"o\">.</span>AdminURLFieldWidget<span class=\"p\">()</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertHTMLEqual<span class=\"p\">(</span>\n            conditional_escape<span class=\"p\">(</span>w<span class=\"o\">.</span>render<span class=\"p\">(</span><span class=\"s1\">&#39;test&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;http://example-äüö.com&#39;</span><span class=\"p\">)),</span>\n            <span class=\"s1\">&#39;&lt;p class=&quot;url&quot;&gt;Currently:&lt;a href=&quot;http://xn--example--7za4pnc.com&quot;&gt;http://example-äüö.com&lt;/a&gt;&lt;br /&gt;Change:&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; value=&quot;http://example-äüö.com&quot; /&gt;&lt;/p&gt;&#39;</span>\n        <span class=\"p\">)</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">test_render_quoting</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        w <span class=\"o\">=</span> widgets<span class=\"o\">.</span>AdminURLFieldWidget<span class=\"p\">()</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertHTMLEqual<span class=\"p\">(</span>\n            conditional_escape<span class=\"p\">(</span>w<span class=\"o\">.</span>render<span class=\"p\">(</span><span class=\"s1\">&#39;test&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;http://example.com/&lt;sometag&gt;some text&lt;/sometag&gt;&#39;</span><span class=\"p\">)),</span>\n            <span class=\"s1\">&#39;&lt;p class=&quot;url&quot;&gt;Currently:&lt;a href=&quot;http://example.com/%3Csometag</span><span class=\"si\">%3E</span><span class=\"s1\">some%20text%3C/sometag</span><span class=\"si\">%3E</span><span class=\"s1\">&quot;&gt;http://example.com/&amp;lt;sometag&amp;gt;some text&amp;lt;/sometag&amp;gt;&lt;/a&gt;&lt;br /&gt;Change:&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; value=&quot;http://example.com/&lt;sometag&gt;some text&lt;/sometag&gt;&quot; /&gt;&lt;/p&gt;&#39;</span>\n        <span class=\"p\">)</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertHTMLEqual<span class=\"p\">(</span>\n            conditional_escape<span class=\"p\">(</span>w<span class=\"o\">.</span>render<span class=\"p\">(</span><span class=\"s1\">&#39;test&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;http://example-äüö.com/&lt;sometag&gt;some text&lt;/sometag&gt;&#39;</span><span class=\"p\">)),</span>\n            <span class=\"s1\">&#39;&lt;p class=&quot;url&quot;&gt;Currently:&lt;a href=&quot;http://xn--example--7za4pnc.com/%3Csometag</span><span class=\"si\">%3E</span><span class=\"s1\">some%20text%3C/sometag</span><span class=\"si\">%3E</span><span class=\"s1\">&quot;&gt;http://example-äüö.com/&amp;lt;sometag&amp;gt;some text&amp;lt;/sometag&amp;gt;&lt;/a&gt;&lt;br /&gt;Change:&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; value=&quot;http://example-äüö.com/&lt;sometag&gt;some text&lt;/sometag&gt;&quot; /&gt;&lt;/p&gt;&#39;</span>\n        <span class=\"p\">)</span>\n</code></pre></div>\n<p>The new tests check to see that the <code class=\"docutils literal notranslate\">render</code> method we’ll be adding works\ncorrectly in a couple different situations.</p>\n<aside class=\"admonition-but-this-testing-thing-looks-kinda-hard admonition\" role=\"note\">\n<p class=\"admonition-title\">But this testing thing looks kinda hard…</p>\n<p>If you’ve never had to deal with tests before, they can look a little hard\nto write at first glance. Fortunately, testing is a <em>very</em> big subject in\ncomputer programming, so there’s lots of information out there:</p>\n<ul class=\"simple\">\n<li><p>A good first look at writing tests for Django can be found in the\ndocumentation on <a class=\"reference internal\" href=\"/en/1.8/topics/testing/overview/\"><span class=\"doc\">Writing and running tests</span></a>.</p></li>\n<li><p>Dive Into Python (a free online book for beginning Python developers)\nincludes a great <a class=\"reference external\" href=\"http://www.diveintopython.net/unit_testing/index.html\">introduction to Unit Testing</a>.</p></li>\n<li><p>After reading those, if you want something a little meatier to sink\nyour teeth into, there’s always the <a class=\"reference external\" href=\"https://docs.python.org/library/unittest.html\">Python unittest documentation</a>.</p></li>\n</ul>\n</aside>\n</section>\n<section id=\"running-your-new-test\">\n<h3>Running your new test<a class=\"heading-anchor\" href=\"#running-your-new-test\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Remember that we haven’t actually made any modifications to\n<code class=\"docutils literal notranslate\">AdminURLFieldWidget</code> yet, so our tests are going to fail. Let’s run all the\ntests in the <code class=\"docutils literal notranslate\">model_forms_regress</code> folder to make sure that’s really what\nhappens. From the command line, <code class=\"docutils literal notranslate\">cd</code> into the Django <code class=\"docutils literal notranslate\">tests/</code> directory\nand run:</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>PYTHONPATH<span class=\"o\">=..</span> python runtests<span class=\"o\">.</span>py <span class=\"o\">--</span>settings<span class=\"o\">=</span>test_sqlite admin_widgets\n</code></pre></div>\n<p>If the tests ran correctly, you should see three failures corresponding to each\nof the test methods we added. If all of the tests passed, then you’ll want to\nmake sure that you added the new test shown above to the appropriate folder and\nclass.</p>\n</section>\n</section>\n<section id=\"writing-the-code-for-your-ticket\">\n<h2>Writing the code for your ticket<a class=\"heading-anchor\" href=\"#writing-the-code-for-your-ticket\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Next we’ll be adding the functionality described in ticket <a class=\"extlink-ticket reference external\" href=\"https://code.djangoproject.com/ticket/17549\">#17549</a> to\nDjango.</p>\n<section id=\"writing-the-code-for-ticket-17549\">\n<h3>Writing the code for ticket #17549<a class=\"heading-anchor\" href=\"#writing-the-code-for-ticket-17549\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Navigate to the <code class=\"docutils literal notranslate\">django/django/contrib/admin/</code> folder and open the\n<code class=\"docutils literal notranslate\">widgets.py</code> file. Find the <code class=\"docutils literal notranslate\">AdminURLFieldWidget</code> class on line 302 and add\nthe following <code class=\"docutils literal notranslate\">render</code> method after the existing <code class=\"docutils literal notranslate\">__init__</code> method:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">render</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> name<span class=\"p\">,</span> value<span class=\"p\">,</span> attrs<span class=\"o\">=</span><span class=\"kc\">None</span><span class=\"p\">):</span>\n    html <span class=\"o\">=</span> <span class=\"nb\">super</span><span class=\"p\">(</span>AdminURLFieldWidget<span class=\"p\">,</span> <span class=\"bp\">self</span><span class=\"p\">)</span><span class=\"o\">.</span>render<span class=\"p\">(</span>name<span class=\"p\">,</span> value<span class=\"p\">,</span> attrs<span class=\"p\">)</span>\n    <span class=\"k\">if</span> value<span class=\"p\">:</span>\n        value <span class=\"o\">=</span> force_text<span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>_format_value<span class=\"p\">(</span>value<span class=\"p\">))</span>\n        final_attrs <span class=\"o\">=</span> <span class=\"p\">{</span><span class=\"s1\">&#39;href&#39;</span><span class=\"p\">:</span> mark_safe<span class=\"p\">(</span>smart_urlquote<span class=\"p\">(</span>value<span class=\"p\">))}</span>\n        html <span class=\"o\">=</span> format_html<span class=\"p\">(</span>\n            <span class=\"s1\">&#39;&lt;p class=&quot;url&quot;&gt;</span><span class=\"si\">{}</span><span class=\"s1\"> &lt;a </span><span class=\"si\">{}</span><span class=\"s1\">&gt;</span><span class=\"si\">{}</span><span class=\"s1\">&lt;/a&gt;&lt;br /&gt;</span><span class=\"si\">{}</span><span class=\"s1\"> </span><span class=\"si\">{}</span><span class=\"s1\">&lt;/p&gt;&#39;</span><span class=\"p\">,</span>\n            _<span class=\"p\">(</span><span class=\"s1\">&#39;Currently:&#39;</span><span class=\"p\">),</span> flatatt<span class=\"p\">(</span>final_attrs<span class=\"p\">),</span> value<span class=\"p\">,</span>\n            _<span class=\"p\">(</span><span class=\"s1\">&#39;Change:&#39;</span><span class=\"p\">),</span> html\n        <span class=\"p\">)</span>\n    <span class=\"k\">return</span> html\n</code></pre></div>\n</section>\n<section id=\"verifying-your-test-now-passes\">\n<h3>Verifying your test now passes<a class=\"heading-anchor\" href=\"#verifying-your-test-now-passes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Once you’re done modifying Django, we need to make sure that the tests we wrote\nearlier pass, so we can see whether the code we wrote above is working\ncorrectly. To run the tests in the <code class=\"docutils literal notranslate\">admin_widgets</code> folder, <code class=\"docutils literal notranslate\">cd</code> into the\nDjango <code class=\"docutils literal notranslate\">tests/</code> directory and run:</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>PYTHONPATH<span class=\"o\">=..</span> python runtests<span class=\"o\">.</span>py <span class=\"o\">--</span>settings<span class=\"o\">=</span>test_sqlite admin_widgets\n</code></pre></div>\n<p>Oops, good thing we wrote those tests! You should still see 3 failures with\nthe following exception:</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=\"ne\">NameError</span><span class=\"p\">:</span> <span class=\"k\">global</span> name <span class=\"s1\">&#39;smart_urlquote&#39;</span> <span class=\"ow\">is</span> <span class=\"ow\">not</span> defined\n</code></pre></div>\n<p>We forgot to add the import for that method.  Go ahead and add the\n<code class=\"docutils literal notranslate\">smart_urlquote</code> import at the end of line 13 of\n<code class=\"docutils literal notranslate\">django/contrib/admin/widgets.py</code> so it looks as follows:</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=\"nn\">django.utils.html</span> <span class=\"kn\">import</span> escape<span class=\"p\">,</span> format_html<span class=\"p\">,</span> format_html_join<span class=\"p\">,</span> smart_urlquote\n</code></pre></div>\n<p>Re-run the tests and everything should pass. If it doesn’t, make sure you\ncorrectly modified the <code class=\"docutils literal notranslate\">AdminURLFieldWidget</code> class as shown above and\ncopied the new tests correctly.</p>\n</section>\n</section>\n<section id=\"running-django-s-test-suite-for-the-second-time\">\n<h2>Running Django’s test suite for the second time<a class=\"heading-anchor\" href=\"#running-django-s-test-suite-for-the-second-time\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Once you’ve verified that your patch and your test are working correctly, it’s\na good idea to run the entire Django test suite just to verify that your change\nhasn’t introduced any bugs into other areas of Django. While successfully\npassing the entire test suite doesn’t guarantee your code is bug free, it does\nhelp identify many bugs and regressions that might otherwise go unnoticed.</p>\n<p>To run the entire Django test suite, <code class=\"docutils literal notranslate\">cd</code> into the Django <code class=\"docutils literal notranslate\">tests/</code>\ndirectory and run:</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>PYTHONPATH<span class=\"o\">=..</span> python runtests<span class=\"o\">.</span>py <span class=\"o\">--</span>settings<span class=\"o\">=</span>test_sqlite\n</code></pre></div>\n<p>As long as you don’t see any failures, you’re good to go. Note that this fix\nalso made a <a class=\"reference external\" href=\"https://github.com/django/django/commit/ac2052ebc84c45709ab5f0f25e685bf656ce79bc#diff-0\">small CSS change</a> to format the new widget. You can make the\nchange if you’d like, but we’ll skip it for now in the interest of brevity.</p>\n</section>\n<section id=\"writing-documentation\">\n<h2>Writing Documentation<a class=\"heading-anchor\" href=\"#writing-documentation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>This is a new feature, so it should be documented.  Add the following on line\n925 of <code class=\"docutils literal notranslate\">django/docs/ref/models/fields.txt</code> beneath the existing docs for\n<code class=\"docutils literal notranslate\">URLField</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> versionadded<span class=\"p\">::</span> <span class=\"mf\">1.5</span>\n\n    The current value of the field will be displayed <span class=\"k\">as</span> a clickable link above the\n    <span class=\"nb\">input</span> widget<span class=\"o\">.</span>\n</code></pre></div>\n<p>For more information on writing documentation, including an explanation of what\nthe <code class=\"docutils literal notranslate\">versionadded</code> bit is all about, see\n<a class=\"reference internal\" href=\"/en/1.8/internals/contributing/writing-documentation/\"><span class=\"doc\">Writing documentation</span></a>. That page also includes\nan explanation of how to build a copy of the documentation locally, so you can\npreview the HTML that will be generated.</p>\n</section>\n<section id=\"generating-a-patch-for-your-changes\">\n<h2>Generating a patch for your changes<a class=\"heading-anchor\" href=\"#generating-a-patch-for-your-changes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Now it’s time to generate a patch file that can be uploaded to Trac or applied\nto another copy of Django. To get a look at the content of your patch, run the\nfollowing command:</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>git diff\n</code></pre></div>\n<p>This will display the differences between your current copy of Django (with\nyour changes) and the revision that you initially checked out earlier in the\ntutorial.</p>\n<p>Once you’re done looking at the patch, hit the <code class=\"docutils literal notranslate\">q</code> key to exit back to the\ncommand line.  If the patch’s content looked okay, you can run the following\ncommand to save the patch file to your current working directory:</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>git diff <span class=\"o\">&gt;</span> <span class=\"mf\">17549.</span>diff\n</code></pre></div>\n<p>You should now have a file in the root Django directory called <code class=\"docutils literal notranslate\">17549.diff</code>.\nThis patch file contains all your changes and should look this:</p>\n<div class=\"code-block\" data-language=\"diff\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Diff</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=\"Diff code\"><code><span class=\"gh\">diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py</span>\n<span class=\"gh\">index 1e0bc2d..9e43a10 100644</span>\n<span class=\"gd\">--- a/django/contrib/admin/widgets.py</span>\n<span class=\"gi\">+++ b/django/contrib/admin/widgets.py</span>\n<span class=\"gu\">@@ -10,7 +10,7 @@ from django.contrib.admin.templatetags.admin_static import static</span>\n from django.core.urlresolvers import reverse\n from django.forms.widgets import RadioFieldRenderer\n from django.forms.util import flatatt\n<span class=\"gd\">-from django.utils.html import escape, format_html, format_html_join</span>\n<span class=\"gi\">+from django.utils.html import escape, format_html, format_html_join, smart_urlquote</span>\n from django.utils.text import Truncator\n from django.utils.translation import ugettext as _\n from django.utils.safestring import mark_safe\n<span class=\"gu\">@@ -306,6 +306,18 @@ class AdminURLFieldWidget(forms.TextInput):</span>\n             final_attrs.update(attrs)\n         super(AdminURLFieldWidget, self).__init__(attrs=final_attrs)\n\n<span class=\"gi\">+    def render(self, name, value, attrs=None):</span>\n<span class=\"gi\">+        html = super(AdminURLFieldWidget, self).render(name, value, attrs)</span>\n<span class=\"gi\">+        if value:</span>\n<span class=\"gi\">+            value = force_text(self._format_value(value))</span>\n<span class=\"gi\">+            final_attrs = {&#39;href&#39;: mark_safe(smart_urlquote(value))}</span>\n<span class=\"gi\">+            html = format_html(</span>\n<span class=\"gi\">+                &#39;&lt;p class=&quot;url&quot;&gt;{} &lt;a {}&gt;{}&lt;/a&gt;&lt;br /&gt;{} {}&lt;/p&gt;&#39;,</span>\n<span class=\"gi\">+                _(&#39;Currently:&#39;), flatatt(final_attrs), value,</span>\n<span class=\"gi\">+                _(&#39;Change:&#39;), html</span>\n<span class=\"gi\">+            )</span>\n<span class=\"gi\">+        return html</span>\n<span class=\"gi\">+</span>\n class AdminIntegerFieldWidget(forms.TextInput):\n     class_name = &#39;vIntegerField&#39;\n\n<span class=\"gh\">diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt</span>\n<span class=\"gh\">index 809d56e..d44f85f 100644</span>\n<span class=\"gd\">--- a/docs/ref/models/fields.txt</span>\n<span class=\"gi\">+++ b/docs/ref/models/fields.txt</span>\n<span class=\"gu\">@@ -922,6 +922,10 @@ Like all :class:`CharField` subclasses, :class:`URLField` takes the optional</span>\n :attr:`~CharField.max_length`argument. If you don&#39;t specify\n :attr:`~CharField.max_length`, a default of 200 is used.\n\n<span class=\"gi\">+.. versionadded:: 1.5</span>\n<span class=\"gi\">+</span>\n<span class=\"gi\">+The current value of the field will be displayed as a clickable link above the</span>\n<span class=\"gi\">+input widget.</span>\n\n Relationship fields\n ===================\n<span class=\"gh\">diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py</span>\n<span class=\"gh\">index 4b11543..94acc6d 100644</span>\n<span class=\"gd\">--- a/tests/regressiontests/admin_widgets/tests.py</span>\n<span class=\"gi\">+++ b/tests/regressiontests/admin_widgets/tests.py</span>\n\n<span class=\"gu\">@@ -265,6 +265,35 @@ class AdminSplitDateTimeWidgetTest(DjangoTestCase):</span>\n                     &#39;&lt;p class=&quot;datetime&quot;&gt;Datum: &lt;input value=&quot;01.12.2007&quot; type=&quot;text&quot; class=&quot;vDateField&quot; name=&quot;test_0&quot; size=&quot;10&quot; /&gt;&lt;br /&gt;Zeit: &lt;input value=&quot;09:30:00&quot; type=&quot;text&quot; class=&quot;vTimeField&quot; name=&quot;test_1&quot; size=&quot;8&quot; /&gt;&lt;/p&gt;&#39;,\n                 )\n\n<span class=\"gi\">+class AdminURLWidgetTest(DjangoTestCase):</span>\n<span class=\"gi\">+    def test_render(self):</span>\n<span class=\"gi\">+        w = widgets.AdminURLFieldWidget()</span>\n<span class=\"gi\">+        self.assertHTMLEqual(</span>\n<span class=\"gi\">+            conditional_escape(w.render(&#39;test&#39;, &#39;&#39;)),</span>\n<span class=\"gi\">+            &#39;&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; /&gt;&#39;</span>\n<span class=\"gi\">+        )</span>\n<span class=\"gi\">+        self.assertHTMLEqual(</span>\n<span class=\"gi\">+            conditional_escape(w.render(&#39;test&#39;, &#39;http://example.com&#39;)),</span>\n<span class=\"gi\">+            &#39;&lt;p class=&quot;url&quot;&gt;Currently:&lt;a href=&quot;http://example.com&quot;&gt;http://example.com&lt;/a&gt;&lt;br /&gt;Change:&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; value=&quot;http://example.com&quot; /&gt;&lt;/p&gt;&#39;</span>\n<span class=\"gi\">+        )</span>\n<span class=\"gi\">+</span>\n<span class=\"gi\">+    def test_render_idn(self):</span>\n<span class=\"gi\">+        w = widgets.AdminURLFieldWidget()</span>\n<span class=\"gi\">+        self.assertHTMLEqual(</span>\n<span class=\"gi\">+            conditional_escape(w.render(&#39;test&#39;, &#39;http://example-äüö.com&#39;)),</span>\n<span class=\"gi\">+            &#39;&lt;p class=&quot;url&quot;&gt;Currently:&lt;a href=&quot;http://xn--example--7za4pnc.com&quot;&gt;http://example-äüö.com&lt;/a&gt;&lt;br /&gt;Change:&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; value=&quot;http://example-äüö.com&quot; /&gt;&lt;/p&gt;&#39;</span>\n<span class=\"gi\">+        )</span>\n<span class=\"gi\">+</span>\n<span class=\"gi\">+    def test_render_quoting(self):</span>\n<span class=\"gi\">+        w = widgets.AdminURLFieldWidget()</span>\n<span class=\"gi\">+        self.assertHTMLEqual(</span>\n<span class=\"gi\">+            conditional_escape(w.render(&#39;test&#39;, &#39;http://example.com/&lt;sometag&gt;some text&lt;/sometag&gt;&#39;)),</span>\n<span class=\"gi\">+            &#39;&lt;p class=&quot;url&quot;&gt;Currently:&lt;a href=&quot;http://example.com/%3Csometag%3Esome%20text%3C/sometag%3E&quot;&gt;http://example.com/&amp;lt;sometag&amp;gt;some text&amp;lt;/sometag&amp;gt;&lt;/a&gt;&lt;br /&gt;Change:&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; value=&quot;http://example.com/&lt;sometag&gt;some text&lt;/sometag&gt;&quot; /&gt;&lt;/p&gt;&#39;</span>\n<span class=\"gi\">+        )</span>\n<span class=\"gi\">+        self.assertHTMLEqual(</span>\n<span class=\"gi\">+            conditional_escape(w.render(&#39;test&#39;, &#39;http://example-äüö.com/&lt;sometag&gt;some text&lt;/sometag&gt;&#39;)),</span>\n<span class=\"gi\">+            &#39;&lt;p class=&quot;url&quot;&gt;Currently:&lt;a href=&quot;http://xn--example--7za4pnc.com/%3Csometag%3Esome%20text%3C/sometag%3E&quot;&gt;http://example-äüö.com/&amp;lt;sometag&amp;gt;some text&amp;lt;/sometag&amp;gt;&lt;/a&gt;&lt;br /&gt;Change:&lt;input class=&quot;vURLField&quot; name=&quot;test&quot; type=&quot;text&quot; value=&quot;http://example-äüö.com/&lt;sometag&gt;some text&lt;/sometag&gt;&quot; /&gt;&lt;/p&gt;&#39;</span>\n<span class=\"gi\">+        )</span>\n\n class AdminFileWidgetTest(DjangoTestCase):\n     def test_render(self):\n</code></pre></div>\n</section>\n<section id=\"so-what-do-i-do-next\">\n<h2>So what do I do next?<a class=\"heading-anchor\" href=\"#so-what-do-i-do-next\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Congratulations, you’ve generated your very first Django patch! Now that you’ve\ngot that under your belt, you can put those skills to good use by helping to\nimprove Django’s codebase. Generating patches and attaching them to Trac\ntickets is useful, however, since we are using git - adopting a more <a class=\"reference internal\" href=\"/en/1.8/internals/contributing/writing-code/working-with-git/\"><span class=\"doc\">git\noriented workflow</span></a> is\nrecommended.</p>\n<p>Since we never committed our changes locally, perform the following to get your\ngit branch back to a good starting point:</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>git reset <span class=\"o\">--</span>hard HEAD\ngit checkout master\n</code></pre></div>\n<section id=\"more-information-for-new-contributors\">\n<h3>More information for new contributors<a class=\"heading-anchor\" href=\"#more-information-for-new-contributors\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Before you get too into writing patches for Django, there’s a little more\ninformation on contributing that you should probably take a look at:</p>\n<ul class=\"simple\">\n<li><p>You should make sure to read Django’s documentation on\n<a class=\"reference internal\" href=\"/en/1.8/internals/contributing/writing-code/submitting-patches/\"><span class=\"doc\">claiming tickets and submitting patches</span></a>.\nIt covers Trac etiquette, how to claim tickets for yourself, expected\ncoding style for patches, and many other important details.</p></li>\n<li><p>First time contributors should also read Django’s <a class=\"reference internal\" href=\"/en/1.8/internals/contributing/new-contributors/\"><span class=\"doc\">documentation\nfor first time contributors</span></a>.\nIt has lots of good advice for those of us who are new to helping out\nwith Django.</p></li>\n<li><p>After those, if you’re still hungry for more information about\ncontributing, you can always browse through the rest of\n<a class=\"reference internal\" href=\"/en/1.8/internals/contributing/\"><span class=\"doc\">Django’s documentation on contributing</span></a>.\nIt contains a ton of useful information and should be your first source\nfor answering any questions you might have.</p></li>\n</ul>\n</section>\n<section id=\"finding-your-first-real-ticket\">\n<h3>Finding your first real ticket<a class=\"heading-anchor\" href=\"#finding-your-first-real-ticket\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Once you’ve looked through some of that information, you’ll be ready to go out\nand find a ticket of your own to write a patch for. Pay special attention to\ntickets with the “easy pickings” criterion. These tickets are often much\nsimpler in nature and are great for first time contributors.  Once you’re\nfamiliar with contributing to Django, you can move on to writing patches for\nmore difficult and complicated tickets.</p>\n<p>If you just want to get started already (and nobody would blame you!), try\ntaking a look at the list of <a class=\"reference external\" href=\"https://code.djangoproject.com/query?status=new&amp;status=reopened&amp;has_patch=0&amp;easy=1&amp;col=id&amp;col=summary&amp;col=status&amp;col=owner&amp;col=type&amp;col=milestone&amp;order=priority\">easy tickets that need patches</a> and the\n<a class=\"reference external\" href=\"https://code.djangoproject.com/query?status=new&amp;status=reopened&amp;needs_better_patch=1&amp;easy=1&amp;col=id&amp;col=summary&amp;col=status&amp;col=owner&amp;col=type&amp;col=milestone&amp;order=priority\">easy tickets that have patches which need improvement</a>. If you’re familiar\nwith writing tests, you can also look at the list of\n<a class=\"reference external\" href=\"https://code.djangoproject.com/query?status=new&amp;status=reopened&amp;needs_tests=1&amp;easy=1&amp;col=id&amp;col=summary&amp;col=status&amp;col=owner&amp;col=type&amp;col=milestone&amp;order=priority\">easy tickets that need tests</a>. Just remember to follow the guidelines about\nclaiming tickets that were mentioned in the link to Django’s documentation on\n<a class=\"reference internal\" href=\"/en/1.8/internals/contributing/writing-code/submitting-patches/\"><span class=\"doc\">claiming tickets and submitting patches</span></a>.</p>\n</section>\n<section id=\"what-s-next\">\n<h3>What’s next?<a class=\"heading-anchor\" href=\"#what-s-next\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>After a ticket has a patch, it needs to be reviewed by a second set of eyes.\nAfter uploading a patch or submitting a pull request, be sure to update the\nticket metadata by setting the flags on the ticket to say “has patch”,\n“doesn’t need tests”, etc, so others can find it for review. Contributing\ndoesn’t necessarily always mean writing a patch from scratch. Reviewing\nexisting patches is also a very helpful contribution. See\n<a class=\"reference internal\" href=\"/en/1.8/internals/contributing/triaging-tickets/\"><span class=\"doc\">Triaging tickets</span></a> for details.</p>\n</section>\n</section>","rootId":"writing-your-first-patch-for-django","toc":[{"title":"Introduction","anchor":"introduction","children":[{"title":"Who’s this tutorial for?","anchor":"who-s-this-tutorial-for","children":[]},{"title":"What does this tutorial cover?","anchor":"what-does-this-tutorial-cover","children":[]}]},{"title":"Installing Git","anchor":"installing-git","children":[]},{"title":"Getting a copy of Django’s development version","anchor":"getting-a-copy-of-django-s-development-version","children":[]},{"title":"Rolling back to a previous revision of Django","anchor":"rolling-back-to-a-previous-revision-of-django","children":[]},{"title":"Running Django’s test suite for the first time","anchor":"running-django-s-test-suite-for-the-first-time","children":[]},{"title":"Writing some tests for your ticket","anchor":"writing-some-tests-for-your-ticket","children":[{"title":"Writing some tests for ticket #17549","anchor":"writing-some-tests-for-ticket-17549","children":[]},{"title":"Running your new test","anchor":"running-your-new-test","children":[]}]},{"title":"Writing the code for your ticket","anchor":"writing-the-code-for-your-ticket","children":[{"title":"Writing the code for ticket #17549","anchor":"writing-the-code-for-ticket-17549","children":[]},{"title":"Verifying your test now passes","anchor":"verifying-your-test-now-passes","children":[]}]},{"title":"Running Django’s test suite for the second time","anchor":"running-django-s-test-suite-for-the-second-time","children":[]},{"title":"Writing Documentation","anchor":"writing-documentation","children":[]},{"title":"Generating a patch for your changes","anchor":"generating-a-patch-for-your-changes","children":[]},{"title":"So what do I do next?","anchor":"so-what-do-i-do-next","children":[{"title":"More information for new contributors","anchor":"more-information-for-new-contributors","children":[]},{"title":"Finding your first real ticket","anchor":"finding-your-first-real-ticket","children":[]},{"title":"What’s next?","anchor":"what-s-next","children":[]}]}],"breadcrumbs":[{"docname":"intro/index","title":"Getting started","url":"/en/1.8/intro/"}],"prev":{"docname":"intro/whatsnext","title":"What to read next","url":"/en/1.8/intro/whatsnext/"},"next":{"docname":"topics/index","title":"Using Django","url":"/en/1.8/topics/"},"formats":{"html":"/en/1.8/intro/contributing/","markdown":"/en/1.8/intro/contributing.md","json":"/en/1.8/intro/contributing.json"},"source":"https://github.com/django/django/blob/stable/1.8.x/docs/intro/contributing.txt","official":"https://docs.djangoproject.com/en/1.8/intro/contributing/","inVersions":["dev","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","1.11","1.10","1.9","1.8"],"inLocales":["en"]}