{"title":"Tutorial avançado: Como escrever aplicações reutilizáveis","version":"5.1","locale":"pt-br","docname":"intro/reusable-apps","url":"/pt-br/5.1/intro/reusable-apps/","canonical":"https://djangodocs.dev/pt-br/5.1/intro/reusable-apps/","summary":"This advanced tutorial begins where Tutorial 8 left off. We’ll be turning our web-poll into a standalone Python package you can reuse in new projects and…","html":"<h1>Tutorial avançado: Como escrever aplicações reutilizáveis<a class=\"heading-anchor\" href=\"#advanced-tutorial-how-to-write-reusable-apps\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>This advanced tutorial begins where <a class=\"reference internal\" href=\"/pt-br/5.1/intro/tutorial08/\"><span class=\"doc\">Tutorial 8</span></a>\nleft off. We’ll be turning our web-poll into a standalone Python package\nyou can reuse in new projects and share with other people.</p>\n<p>If you haven’t recently completed Tutorials 1–8, we encourage you to review\nthese so that your example project matches the one described below.</p>\n<section id=\"reusability-matters\">\n<h2>Reutilização importa<a class=\"heading-anchor\" href=\"#reusability-matters\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>É um grande trabalho projetar, contruir, testar e manter uma aplicação web. Muitos projetos Python e Django compartilham problemas em comum. Não seria ótimo se nós pudessemos economizar um pouco desse trabalho repetido?</p>\n<p>Reusability is the way of life in Python. <a class=\"reference external\" href=\"https://pypi.org/\">The Python Package Index (PyPI)</a> has a vast range of packages you can use in your own\nPython programs. Check out <a class=\"reference external\" href=\"https://djangopackages.org\">Django Packages</a> for\nexisting reusable apps you could incorporate in your project. Django itself is\nalso a normal Python package. This means that you can take existing Python\npackages or Django apps and compose them into your own web project. You only\nneed to write the parts that make your project unique.</p>\n<p>Vamos dizer que você está iniciando um projeto que precisa de uma aplicação de enquetes como a que estivemos trabalhando. Como fazer essa aplicação reutilizável? Sua sorte é que é que você já está no caminho. Em <a class=\"reference internal\" href=\"/pt-br/5.1/intro/tutorial01/\"><span class=\"doc\">Tutorial</span></a>, vimos como podemos desacoplar a enquete do URLconf do projeto usando um <code class=\"docutils literal notranslate\">include</code>. Neste tutorial, iremos adiante para tornar a aplicação fácil de usar em novos projetos e pronta para publicar para outros instalarem e usarem.</p>\n<aside class=\"admonition-package-app admonition\" role=\"note\">\n<p class=\"admonition-title\">Pacote? Aplicação?</p>\n<p>Um <span class=\"xref std std-term\">pacote</span> Python fornece uma maneira de agrupar códigos Python relacionados para fácil reutilização. Um pacote contém um ou mais arquivos de códigos Python (também conhecidos como “módulos”).</p>\n<p>Um pacote pode ser importado com <code class=\"docutils literal notranslate\">import foo.bar</code> ou <code class=\"docutils literal notranslate\">from foo import bar</code>. Para um diretório (como <code class=\"docutils literal notranslate\">polls</code>) formar um pacote, ele deve conter um arquivo especial <code class=\"docutils literal notranslate\">__init__.py</code>, mesmo se este arquivo estiver vazio.</p>\n<p>Uma <em>aplicação</em> Django é um pacote Python especificamente destinado para usar em um projeto Django. Uma aplicação pode usar convenções comuns do Django, tais como ter submódulos <code class=\"docutils literal notranslate\">models</code>, <code class=\"docutils literal notranslate\">tests</code>, <code class=\"docutils literal notranslate\">urls</code>, e <code class=\"docutils literal notranslate\">views</code>.</p>\n<p>Posteriormente usamos o termo <em>empacotamento</em> para descrever o processo de tornar um pacote Python fácil para outros instalarem. Pode ser um pouco confuso, nós sabemos.</p>\n</aside>\n</section>\n<section id=\"your-project-and-your-reusable-app\">\n<h2>Seu projeto e sua aplicação reutilizável<a class=\"heading-anchor\" href=\"#your-project-and-your-reusable-app\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>After the previous tutorials, our project should look like this:</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>djangotutorial/\n    manage.py\n    mysite/\n        __init__.py\n        settings.py\n        urls.py\n        asgi.py\n        wsgi.py\n    polls/\n        __init__.py\n        admin.py\n        apps.py\n        migrations/\n            __init__.py\n            0001_initial.py\n        models.py\n        static/\n            polls/\n                images/\n                    background.png\n                style.css\n        templates/\n            polls/\n                detail.html\n                index.html\n                results.html\n        tests.py\n        urls.py\n        views.py\n    templates/\n        admin/\n            base_site.html\n</code></pre></div>\n<p>You created <code class=\"docutils literal notranslate\">djangotutorial/templates</code> in <a class=\"reference internal\" href=\"/pt-br/5.1/intro/tutorial07/\"><span class=\"doc\">Tutorial 7</span></a>, and <code class=\"docutils literal notranslate\">polls/templates</code> in\n<a class=\"reference internal\" href=\"/pt-br/5.1/intro/tutorial03/\"><span class=\"doc\">Tutorial 3</span></a>. Now perhaps it is clearer why we chose\nto have separate template directories for the project and application:\neverything that is part of the polls application is in <code class=\"docutils literal notranslate\">polls</code>. It makes the\napplication self-contained and easier to drop into a new project.</p>\n<p>O diretório <code class=\"docutils literal notranslate\">polls</code> poderia agora ser copiado em um novo projeto Django, e imediatamente reusada. Embora não esteja já pronta para ser publicada. Para isso, nós precisamos empacotar a aplicação para tornar fácil para outros instalarem.</p>\n</section>\n<section id=\"installing-some-prerequisites\">\n<span id=\"installing-reusable-apps-prerequisites\"></span><h2>Instalando alguns pré-requisitos<a class=\"heading-anchor\" href=\"#installing-some-prerequisites\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The current state of Python packaging is a bit muddled with various tools. For\nthis tutorial, we’re going to use <a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/setuptools/\">setuptools</a> to build our package. It’s\nthe recommended packaging tool (merged with the <code class=\"docutils literal notranslate\">distribute</code> fork). We’ll\nalso be using <a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/pip/\">pip</a> to install and uninstall it. You should install these\ntwo packages now. If you need help, you can refer to <a class=\"reference internal\" href=\"/pt-br/5.1/topics/install/#installing-official-release\"><span class=\"std std-ref\">how to install\nDjango with pip</span></a>. You can install <code class=\"docutils literal notranslate\">setuptools</code>\nthe same way.</p>\n</section>\n<section id=\"packaging-your-app\">\n<h2>Empacotando sua aplicação<a class=\"heading-anchor\" href=\"#packaging-your-app\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><em>Empacotamento</em> Python refere-se a preparar sua aplicação num formato específico que possa ser facilmente instalado e usado. O próprio Django é empacotado de uma maneira muito parecida. Para aplicações pequenas, como a de enquetes, esse processo não é tão difícil.</p>\n<ol class=\"arabic\">\n<li><p>First, create a parent directory for the package, outside of your Django\nproject. Call this directory <code class=\"docutils literal notranslate\">django-polls</code>.</p>\n<aside class=\"admonition-choosing-a-name-for-your-app admonition\" role=\"note\">\n<p class=\"admonition-title\">Escolhendo um nome para a sua aplicação</p>\n<p>When choosing a name for your package, check PyPI to avoid naming\nconflicts with existing packages. We recommend using a <code class=\"docutils literal notranslate\">django-</code>\nprefix for package names, to identify your package as specific to\nDjango, and a corresponding <code class=\"docutils literal notranslate\">django_</code> prefix for your module name. For\nexample, the <code class=\"docutils literal notranslate\">django-ratelimit</code> package contains the\n<code class=\"docutils literal notranslate\">django_ratelimit</code> module.</p>\n<p>Rótulo da aplicação (isto é, a parte final do caminho pontilhado para os pacotes da aplicação) <em>deve</em> ser único no <a class=\"reference internal\" href=\"/pt-br/5.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a>. Evite usar o mesmo rótulo como os do pacote <a class=\"reference internal\" href=\"/pt-br/5.1/ref/contrib/\"><span class=\"doc\">contrib</span></a> do Django, por exemplo <code class=\"docutils literal notranslate\">auth</code>, <code class=\"docutils literal notranslate\">admin</code>, ou <code class=\"docutils literal notranslate\">messages</code>.</p>\n</aside>\n</li>\n<li><p>Move the <code class=\"docutils literal notranslate\">polls</code> directory into <code class=\"docutils literal notranslate\">django-polls</code> directory, and rename it\nto <code class=\"docutils literal notranslate\">django_polls</code>.</p></li>\n<li><p>Edit <code class=\"docutils literal notranslate\">django_polls/apps.py</code> so that <a class=\"reference internal\" href=\"/pt-br/5.1/ref/applications/#django.apps.AppConfig.name\" title=\"django.apps.AppConfig.name\"><code class=\"xref py py-attr docutils literal notranslate\">name</code></a> refers to the\nnew module name and add <a class=\"reference internal\" href=\"/pt-br/5.1/ref/applications/#django.apps.AppConfig.label\" title=\"django.apps.AppConfig.label\"><code class=\"xref py py-attr docutils literal notranslate\">label</code></a> to give a short name for\nthe app:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">django-polls/django_polls/apps.py</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</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=\"Python code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.apps</span> <span class=\"kn\">import</span> AppConfig\n\n\n<span class=\"k\">class</span> <span class=\"nc\">PollsConfig</span><span class=\"p\">(</span>AppConfig<span class=\"p\">):</span>\n    default_auto_field <span class=\"o\">=</span> <span class=\"s2\">&quot;django.db.models.BigAutoField&quot;</span>\n    name <span class=\"o\">=</span> <span class=\"s2\">&quot;django_polls&quot;</span>\n    label <span class=\"o\">=</span> <span class=\"s2\">&quot;polls&quot;</span>\n</code></pre></figure>\n</li>\n<li><p>Crie um arquivo <code class=\"docutils literal notranslate\">django-polls/README.rst</code> com o seguinte conteúdo:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"rst\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">django-polls/README.rst</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Rst</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Rst code\"><code><span class=\"gh\">============</span>\n<span class=\"gh\">django-polls</span>\n<span class=\"gh\">============</span>\n\ndjango-polls is a Django app to conduct web-based polls. For each\nquestion, visitors can choose between a fixed number of answers.\n\nDetailed documentation is in the &quot;docs&quot; directory.\n\n<span class=\"gh\">Quick start</span>\n<span class=\"gh\">-----------</span>\n\n<span class=\"m\">1.</span> Add &quot;polls&quot; to your INSTALLED_APPS setting like this::\n\n    INSTALLED_APPS = [\n<span class=\"c\">        ...,</span>\n<span class=\"c\">        &quot;django_polls&quot;,</span>\n<span class=\"c\">    ]</span>\n\n<span class=\"m\">2.</span> Include the polls URLconf in your project urls.py like this::\n\n    path(&quot;polls/&quot;, include(&quot;django_polls.urls&quot;)),\n\n<span class=\"m\">3.</span> Run <span class=\"s\">``python manage.py migrate``</span> to create the models.\n\n<span class=\"m\">4.</span> Start the development server and visit the admin to create a poll.\n\n<span class=\"m\">5.</span> Visit the <span class=\"s\">``/polls/``</span> URL to participate in the poll.\n</code></pre></figure>\n</li>\n<li><p>Crie um arquivo <code class=\"docutils literal notranslate\">django-polls/LICENSE</code>. Escolher uma licença está fora do escopo deste tutorial, mas é suficiente dizer que código distribuído publicamente sem uma licença é <em>inútil</em>. Djando e muitas aplicações compatíveis com o Django são distribuídas sob a licença BSD; no entanto, você é livre para escolher sua própria licença. Apenas esteja ciente que a escolha da sua licença afetará quem pode usar seu código.</p></li>\n<li><p>Next we’ll create the <code class=\"docutils literal notranslate\">pyproject.toml</code> file which details how to build and\ninstall the app. A full explanation of this file is beyond the scope of this\ntutorial, but the <a class=\"reference external\" href=\"https://packaging.python.org/guides/writing-pyproject-toml/\">Python Packaging User Guide</a> has a good\nexplanation. Create the <code class=\"docutils literal notranslate\">django-polls/pyproject.toml</code> file with the\nfollowing contents:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"toml\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">django-polls/pyproject.toml</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Toml</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=\"Toml code\"><code><span class=\"k\">[build-system]</span>\nrequires <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s2\">&quot;setuptools&gt;=77.0.3&quot;</span><span class=\"p\">]</span>\nbuild-backend <span class=\"o\">=</span> <span class=\"s2\">&quot;setuptools.build_meta&quot;</span>\n\n<span class=\"k\">[project]</span>\nname <span class=\"o\">=</span> <span class=\"s2\">&quot;django-polls&quot;</span>\nversion <span class=\"o\">=</span> <span class=\"s2\">&quot;0.1&quot;</span>\ndependencies <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;django&gt;=X.Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># Replace &quot;X.Y&quot; as appropriate</span>\n<span class=\"p\">]</span>\ndescription <span class=\"o\">=</span> <span class=\"s2\">&quot;A Django app to conduct web-based polls.&quot;</span>\nreadme <span class=\"o\">=</span> <span class=\"s2\">&quot;README.rst&quot;</span>\nlicense <span class=\"o\">=</span> <span class=\"s2\">&quot;BSD-3-Clause&quot;</span>\nrequires-python <span class=\"o\">=</span> <span class=\"s2\">&quot;&gt;= 3.10&quot;</span>\nauthors <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"p\">{</span>name <span class=\"p\">=</span> <span class=\"s2\">&quot;Your Name&quot;</span><span class=\"p\">,</span> email <span class=\"p\">=</span> <span class=\"s2\">&quot;yourname@example.com&quot;</span><span class=\"p\">},</span>\n<span class=\"p\">]</span>\nclassifiers <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;Environment :: Web Environment&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Framework :: Django&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Framework :: Django :: X.Y&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># Replace &quot;X.Y&quot; as appropriate</span>\n    <span class=\"s2\">&quot;Intended Audience :: Developers&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Operating System :: OS Independent&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Programming Language :: Python&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Programming Language :: Python :: 3&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Programming Language :: Python :: 3 :: Only&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Programming Language :: Python :: 3.10&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Programming Language :: Python :: 3.11&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Programming Language :: Python :: 3.12&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Programming Language :: Python :: 3.13&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Topic :: Internet :: WWW/HTTP&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Topic :: Internet :: WWW/HTTP :: Dynamic Content&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n\n<span class=\"k\">[project.urls]</span>\nHomepage <span class=\"o\">=</span> <span class=\"s2\">&quot;https://www.example.com/&quot;</span>\n</code></pre></figure>\n</li>\n<li><p>Many common files and Python modules and packages are included in the\npackage by default. To include additional files, we’ll need to create a\n<code class=\"docutils literal notranslate\">MANIFEST.in</code> file. To include the templates and static files, create a\nfile <code class=\"docutils literal notranslate\">django-polls/MANIFEST.in</code> with the following contents:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"text\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">django-polls/MANIFEST.in</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>recursive-include django_polls/static *\nrecursive-include django_polls/templates *\n</code></pre></figure>\n</li>\n<li><p>It’s optional, but recommended, to include detailed documentation with your\napp. Create an empty directory <code class=\"docutils literal notranslate\">django-polls/docs</code> for future\ndocumentation.</p>\n<p>Note que o diretório <code class=\"docutils literal notranslate\">docs</code> não será incluido no seu pacote a menos que você adicione alguns arquivos para ele. Muitas aplicações Django fornecem sua documentação online através de sites como</p>\n<p>Many Python projects, including Django and Python itself, use <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/quickstart.html\">Sphinx</a> to build\ntheir documentation. If you choose to use Sphinx you can link back to the\nDjango documentation by configuring <a class=\"reference external\" href=\"https://www.sphinx-doc.org/en/master/usage/quickstart.html#intersphinx\">Intersphinx</a>\nand including a value for Django in your project’s <code class=\"docutils literal notranslate\">intersphinx_mapping</code>\nvalue:</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>intersphinx_mapping <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"s2\">&quot;django&quot;</span><span class=\"p\">:</span> <span class=\"p\">(</span>\n        <span class=\"s2\">&quot;https://docs.djangoproject.com/en/stable/&quot;</span><span class=\"p\">,</span>\n        <span class=\"kc\">None</span><span class=\"p\">,</span>\n    <span class=\"p\">),</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>With that in place, you can then cross-link to specific entries, in the\nsame way as in the Django docs, such as\n“<code class=\"docutils literal notranslate\">:attr:`django.test.TransactionTestCase.databases`</code>”.</p>\n</li>\n<li><p>Check that the <a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/build/\">build</a> package is installed (<code class=\"docutils literal notranslate\">python -m pip install\nbuild</code>) and try building your package by running <code class=\"docutils literal notranslate\">python -m build</code> inside\n<code class=\"docutils literal notranslate\">django-polls</code>. This creates a directory called <code class=\"docutils literal notranslate\">dist</code> and builds your\nnew package into source and binary formats, <code class=\"docutils literal notranslate\">django_polls-0.1.tar.gz</code> and\n<code class=\"docutils literal notranslate\">django_polls-0.1-py3-none-any.whl</code>.</p></li>\n</ol>\n<p>Para mais informações sobre empacotamente, veja o <a class=\"reference external\" href=\"https://packaging.python.org/tutorials/packaging-projects/\">Tutorial sobre Empacotamento e Distribuição de Projetos</a>.</p>\n</section>\n<section id=\"using-your-own-package\">\n<h2>Utilizando o seu próprio pacote<a class=\"heading-anchor\" href=\"#using-your-own-package\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Uma vez que movemos o diretório <code class=\"docutils literal notranslate\">polls</code> para fora do projeto, ele não funciona mais. Vamos consertar isso agora ao instalar nosso novo pacote <code class=\"docutils literal notranslate\">django-polls</code>.</p>\n<aside class=\"admonition-installing-as-a-user-library admonition\" role=\"note\">\n<p class=\"admonition-title\">Instalando uma biblioteca de usuário</p>\n<p>Os passos a seguir instalam <code class=\"docutils literal notranslate\">django-polls</code> como uma biblioteca do usuário. Instalação por usuário tem uma série de vantagens sobre a instalação do pacote em todo o sistema, tais como ser utilizável em sistemas onde você não tem acesso de administrador, bem como prevenir o pacote de afetar serviços do sistema e outros usuários da máquina.</p>\n<p>Note that per-user installations can still affect the behavior of system\ntools that run as that user, so using a virtual environment is a more robust\nsolution (see below).</p>\n</aside>\n<ol class=\"arabic\">\n<li><p>To install the package, use pip (you already <a class=\"reference internal\" href=\"#installing-reusable-apps-prerequisites\"><span class=\"std std-ref\">installed it</span></a>, right?):</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>python -m pip install --user django-polls/dist/django_polls-0.1.tar.gz\n</code></pre></div>\n</li>\n<li><p>Update <code class=\"docutils literal notranslate\">mysite/settings.py</code> to point to the new module name:</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>INSTALLED_APPS <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;django_polls.apps.PollsConfig&quot;</span><span class=\"p\">,</span>\n    <span class=\"o\">...</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n</li>\n<li><p>Update <code class=\"docutils literal notranslate\">mysite/urls.py</code> to point to the new module name:</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>urlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;polls/&quot;</span><span class=\"p\">,</span> include<span class=\"p\">(</span><span class=\"s2\">&quot;django_polls.urls&quot;</span><span class=\"p\">)),</span>\n    <span class=\"o\">...</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n</li>\n<li><p>Run the development server to confirm the project continues to work.</p></li>\n</ol>\n</section>\n<section id=\"publishing-your-app\">\n<h2>Publicando sua aplicação<a class=\"heading-anchor\" href=\"#publishing-your-app\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Agora que nós empacotamos e testamos <code class=\"docutils literal notranslate\">django-polls</code>, ele está pronto para ser compartilhado com o mundo! Se isso não foi apenas um exemplo, você pode agora:</p>\n<ul class=\"simple\">\n<li><p>Enviar o pacote por email para um amigo.</p></li>\n<li><p>Enviar o pacote para seu site.</p></li>\n<li><p>Colocar o pacote em um repositório público, tal como <a class=\"reference external\" href=\"https://pypi.org/\">the Python Package Index (PyPI)</a>. <a class=\"reference external\" href=\"https://packaging.python.org\">packaging.python.org</a> tem <a class=\"reference external\" href=\"https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives\">um bom tutorial</a> para fazer isso.</p></li>\n</ul>\n</section>\n<section id=\"installing-python-packages-with-a-virtual-environment\">\n<h2>Instalando pacotes Python com um ambiente virtual<a class=\"heading-anchor\" href=\"#installing-python-packages-with-a-virtual-environment\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Earlier, we installed <code class=\"docutils literal notranslate\">django-polls</code> as a user library. This has some\ndisadvantages:</p>\n<ul class=\"simple\">\n<li><p>Modificar as bibliotecas de usuário pode afetar outros softwares em Python do seu sistema.</p></li>\n<li><p>Você não poderá rodar versões diferentes do seu pacote (ou outros pacotes com o mesmo nome).</p></li>\n</ul>\n<p>Typically, these situations only arise once you’re maintaining several Django\nprojects. When they do, the best solution is to use <a class=\"reference external\" href=\"https://docs.python.org/3/tutorial/venv.html\" title=\"(em Python v3.14)\"><span class=\"xref std std-doc\">venv</span></a>. This tool allows you to maintain multiple isolated\nPython environments, each with its own copy of the libraries and package\nnamespace.</p>\n</section>","rootId":"advanced-tutorial-how-to-write-reusable-apps","toc":[{"title":"Reutilização importa","anchor":"reusability-matters","children":[]},{"title":"Seu projeto e sua aplicação reutilizável","anchor":"your-project-and-your-reusable-app","children":[]},{"title":"Instalando alguns pré-requisitos","anchor":"installing-some-prerequisites","children":[]},{"title":"Empacotando sua aplicação","anchor":"packaging-your-app","children":[]},{"title":"Utilizando o seu próprio pacote","anchor":"using-your-own-package","children":[]},{"title":"Publicando sua aplicação","anchor":"publishing-your-app","children":[]},{"title":"Instalando pacotes Python com um ambiente virtual","anchor":"installing-python-packages-with-a-virtual-environment","children":[]}],"breadcrumbs":[{"docname":"intro/index","title":"Introdução","url":"/pt-br/5.1/intro/"}],"prev":{"docname":"intro/tutorial08","title":"Escrevendo seu primeiro app Django, parte 8","url":"/pt-br/5.1/intro/tutorial08/"},"next":{"docname":"intro/whatsnext","title":"O que ler a seguir","url":"/pt-br/5.1/intro/whatsnext/"},"formats":{"html":"/pt-br/5.1/intro/reusable-apps/","markdown":"/pt-br/5.1/intro/reusable-apps.md","json":"/pt-br/5.1/intro/reusable-apps.json"},"source":"https://github.com/django/django/blob/stable/5.1.x/docs/intro/reusable-apps.txt","official":"https://docs.djangoproject.com/pt-br/5.1/intro/reusable-apps/","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","1.11","1.10","1.9"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}