{"title":"Οδηγός για προχωρημένους: Πως να γράψετε επαναχρησιμοποιήσιμα apps","version":"6.1","locale":"el","docname":"intro/reusable-apps","url":"/el/6.1/intro/reusable-apps/","canonical":"https://djangodocs.dev/el/6.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 share with…","html":"<h1>Οδηγός για προχωρημένους: Πως να γράψετε επαναχρησιμοποιήσιμα apps<a class=\"heading-anchor\" href=\"#advanced-tutorial-how-to-write-reusable-apps\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>This advanced tutorial begins where <a class=\"reference internal\" href=\"/el/6.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>Η επαναχρησιμοποίηση έχει σημασία<a class=\"heading-anchor\" href=\"#reusability-matters\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Απαιτεί πολύ δουλειά για να σχεδιάσετε, χτίσετε, τεστάρετε και διατηρήσετε μια web εφαρμογή (application). Πολλά Python και Django projects μοιράζονται κοινά προβλήματα. Δεν θα ήταν εξαιρετικά αν μπορούσαμε να γλυτώσουμε κάποιο μέρος από αυτή τη ρουτίνα;</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>Let’s say you were starting a new project that needed a polls app like the one\nwe’ve been working on. How do you make this app reusable? Luckily, you’re well\non the way already. In <a class=\"reference internal\" href=\"/el/6.1/intro/tutorial01/\"><span class=\"doc\">Tutorial 1</span></a>, we saw how we\ncould decouple polls from the project-level URLconf using an <code class=\"docutils literal notranslate\"><span class=\"pre\">include</span></code>.\nIn this tutorial, we’ll take further steps to make the app easy to use in new\nprojects and ready to publish for others to install and use.</p>\n<aside class=\"admonition-package-app admonition\">\n<p class=\"admonition-title\">Package? App?</p>\n<p>Ο όρος Python <a class=\"reference external\" href=\"https://docs.python.org/3/glossary.html#term-package\" title=\"(στη Python έκδοση 3.14)\"><span class=\"xref std std-term\">package</span></a> παρέχει έναν τρόπο να ομαδοποιούμε Python κώδικα για εύκολη επαναχρησιμοποίηση. Ένα package περιέχει ένα ή περισσότερα αρχεία από Python κώδικα (επίσης γνωστά και ως «modules»).</p>\n<p>Ένα package μπορεί να γίνει imported με τον κώδικα <code class=\"docutils literal notranslate\"><span class=\"pre\">import</span> <span class=\"pre\">foo.bar</span></code> ή <code class=\"docutils literal notranslate\"><span class=\"pre\">from</span> <span class=\"pre\">foo</span> <span class=\"pre\">import</span> <span class=\"pre\">bar</span></code>. Για να μετατραπεί ένας φάκελος (όπως ο φάκελος <code class=\"docutils literal notranslate\"><span class=\"pre\">polls</span></code>) σε package, θα πρέπει να περιέχει ένα ειδικό αρχείο με το όνομα <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__.py</span></code>, ακόμη και αν αυτό το αρχείο είναι κενό.</p>\n<p>A Django <em>application</em> is a Python package that is specifically intended\nfor use in a Django project. An application may use common Django\nconventions, such as having <code class=\"docutils literal notranslate\"><span class=\"pre\">models</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">tests</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">urls</span></code>, and <code class=\"docutils literal notranslate\"><span class=\"pre\">views</span></code>\nsubmodules.</p>\n<p>Αργότερα χρησιμοποιούμε τον όρο <em>packaging</em> για να περιγράψουμε την διαδικασία που χρειάζεται για να δημιουργηθεί ένα Python package. Μπορεί να σας μπερδεύει λιγάκι. Καταλαβαίνουμε!</p>\n</aside>\n</section>\n<section id=\"your-project-and-your-reusable-app\">\n<h2>Το project σας και η επαναχρησιμοποιήσιμη app<a class=\"heading-anchor\" href=\"#your-project-and-your-reusable-app\"><span class=\"visually-hidden\">Link to this heading</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\"><span class=\"pre\">djangotutorial/templates</span></code> in <a class=\"reference internal\" href=\"/el/6.1/intro/tutorial07/\"><span class=\"doc\">Tutorial 7</span></a>, and <code class=\"docutils literal notranslate\"><span class=\"pre\">polls/templates</span></code> in\n<a class=\"reference internal\" href=\"/el/6.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\"><span class=\"pre\">polls</span></code>. It makes the\napplication self-contained and easier to drop into a new project.</p>\n<p>Ο φάκελο <code class=\"docutils literal notranslate\"><span class=\"pre\">polls</span></code> μπορεί εύκολα να αντιγραφεί σε ένα καινούργιο Django project και αμέσως να επαναχρησιμοποιηθεί. Δεν είναι, όμως, ακόμη έτοιμο να διανεμηθεί (εκδοθεί). Γι’ αυτό θα πρέπει να μετατρέψουμε την εφαρμογή μας σε ένα package για να διευκολύνουμε τους άλλους που θα την εγκαταστήσουν.</p>\n</section>\n<section id=\"installing-some-prerequisites\">\n<span id=\"installing-reusable-apps-prerequisites\"></span><h2>Εγκαθιστώντας μερικά προαπαιτούμενα<a class=\"heading-anchor\" href=\"#installing-some-prerequisites\"><span class=\"visually-hidden\">Link to this heading</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\"><span class=\"pre\">distribute</span></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=\"/el/6.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\"><span class=\"pre\">setuptools</span></code>\nthe same way.</p>\n</section>\n<section id=\"packaging-your-app\">\n<h2>Πακετάροντας το app σας<a class=\"heading-anchor\" href=\"#packaging-your-app\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Το Python <em>packaging</em> αναφέρεται στην προετοιμασία του app σε μια συγκεκριμένη μορφή ούτως ώστε να μπορεί να εγκατασταθεί και να χρησιμοποιηθεί εύκολα. Το Django από μόνο του έχει πακεταριστεί με παρόμοιο τρόπο. Για μικρά apps όπως το polls, αυτή η διαδικασία δεν είναι δύσκολη.</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\"><span class=\"pre\">django-polls</span></code>.</p>\n<aside class=\"admonition-choosing-a-name-for-your-app admonition\">\n<p class=\"admonition-title\">Επιλέγοντας ένα όνομα για την εφαρμογή σας</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\"><span class=\"pre\">django-</span></code>\nprefix for package names, to identify your package as specific to\nDjango, and a corresponding <code class=\"docutils literal notranslate\"><span class=\"pre\">django_</span></code> prefix for your module name. For\nexample, the <code class=\"docutils literal notranslate\"><span class=\"pre\">django-ratelimit</span></code> package contains the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django_ratelimit</span></code> module.</p>\n<p>Τα application labels (δηλαδή, η τελευταία λέξη των application packages στη διαδρομή με τις τελείες) <em>πρέπει</em> να είναι μοναδικό στη ρύθμιση <a class=\"reference internal\" href=\"/el/6.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a>. Αποφύγετε να χρησιμοποιείτε το ίδιο label με οποιοδήποτε από αυτά των Django <a class=\"reference internal\" href=\"/el/6.1/ref/contrib/\"><span class=\"doc\">contrib packages</span></a>, όπως για παράδειγμα <code class=\"docutils literal notranslate\"><span class=\"pre\">auth</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">admin</span></code> ή <code class=\"docutils literal notranslate\"><span class=\"pre\">messages</span></code>.</p>\n</aside>\n</li>\n<li><p>Move the <code class=\"docutils literal notranslate\"><span class=\"pre\">polls</span></code> directory into <code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls</span></code> directory, and rename it\nto <code class=\"docutils literal notranslate\"><span class=\"pre\">django_polls</span></code>.</p></li>\n<li><p>Edit <code class=\"docutils literal notranslate\"><span class=\"pre\">django_polls/apps.py</span></code> so that <a class=\"reference internal\" href=\"/el/6.1/ref/applications/#django.apps.AppConfig.name\" title=\"django.apps.AppConfig.name\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">name</span></code></a> refers to the\nnew module name, add <a class=\"reference internal\" href=\"/el/6.1/ref/applications/#django.apps.AppConfig.label\" title=\"django.apps.AppConfig.label\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">label</span></code></a> to give a short name for\nthe app, and set <a class=\"reference internal\" href=\"/el/6.1/ref/applications/#django.apps.AppConfig.default_auto_field\" title=\"django.apps.AppConfig.default_auto_field\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">default_auto_field</span></code></a> to ensure your\nmigrations are not affected by changes to <a class=\"reference internal\" href=\"/el/6.1/ref/settings/#std-setting-DEFAULT_AUTO_FIELD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_AUTO_FIELD</span></code></a>\nmade by users of your reusable app:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls/django_polls/apps.py</span></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=\"w\"> </span><span class=\"nn\">django.apps</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">AppConfig</span>\n\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">PollsConfig</span><span class=\"p\">(</span><span class=\"n\">AppConfig</span><span class=\"p\">):</span>\n    <span class=\"n\">default_auto_field</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;django.db.models.BigAutoField&quot;</span>\n    <span class=\"n\">name</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;django_polls&quot;</span>\n    <span class=\"n\">label</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;polls&quot;</span>\n</code></pre></figure>\n</li>\n<li><p>Δημιουργήστε ένα αρχείο <code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls/README.rst</span></code> με το ακόλουθο περιεχόμενο:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"rst\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls/README.rst</span></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>Δημιουργήστε ένα αρχείο <code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls/LICENSE</span></code>. Η επιλογή μιας άδειας (license) είναι πέρα από τους σκοπούς αυτού του οδηγού, αλλά αρκεί να πούμε ότι κώδικας που έχει δημοσιευτεί χωρίς άδεια είναι <em>άχρηστος</em>. Το Django και πολλά άλλα συμβατα με το Django apps είναι διανεμημένα κάτω από την BSD άδεια. Ωστόσο, είστε ελεύθεροι να διαλέξετε μια της αρέσκειας σας. Κρατήστε στο μυαλό σας, όμως, ότι η επιλογή της αδείας επηρεάζει το ποιος θα μπορεί να χρησιμοποιήσει τον κώδικα σας.</p></li>\n<li><p>Next we’ll create the <code class=\"docutils literal notranslate\"><span class=\"pre\">pyproject.toml</span></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\"><span class=\"pre\">django-polls/pyproject.toml</span></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\"><span class=\"pre\">django-polls/pyproject.toml</span></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>\n<span class=\"n\">requires</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"p\">[</span><span class=\"s2\">&quot;setuptools&gt;83&quot;</span><span class=\"p\">]</span>\n<span class=\"n\">build-backend</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s2\">&quot;setuptools.build_meta&quot;</span>\n\n<span class=\"k\">[project]</span>\n<span class=\"n\">name</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s2\">&quot;django-polls&quot;</span>\n<span class=\"n\">version</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s2\">&quot;0.1&quot;</span>\n<span class=\"n\">dependencies</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"p\">[</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;django&gt;=X.Y&quot;</span><span class=\"p\">,</span><span class=\"w\">  </span><span class=\"c1\"># Replace &quot;X.Y&quot; as appropriate</span>\n<span class=\"p\">]</span>\n<span class=\"n\">description</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s2\">&quot;A Django app to conduct web-based polls.&quot;</span>\n<span class=\"n\">readme</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s2\">&quot;README.rst&quot;</span>\n<span class=\"n\">license</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s2\">&quot;BSD-3-Clause&quot;</span>\n<span class=\"n\">requires-python</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"s2\">&quot;&gt;= 3.12&quot;</span>\n<span class=\"n\">authors</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"p\">[</span>\n<span class=\"w\">    </span><span class=\"p\">{</span><span class=\"n\">name</span><span class=\"w\"> </span><span class=\"p\">=</span><span class=\"w\"> </span><span class=\"s2\">&quot;Your Name&quot;</span><span class=\"p\">,</span><span class=\"w\"> </span><span class=\"n\">email</span><span class=\"w\"> </span><span class=\"p\">=</span><span class=\"w\"> </span><span class=\"s2\">&quot;yourname@example.com&quot;</span><span class=\"p\">},</span>\n<span class=\"p\">]</span>\n<span class=\"n\">classifiers</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"p\">[</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Environment :: Web Environment&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Framework :: Django&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Framework :: Django :: X.Y&quot;</span><span class=\"p\">,</span><span class=\"w\">  </span><span class=\"c1\"># Replace &quot;X.Y&quot; as appropriate</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Intended Audience :: Developers&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Operating System :: OS Independent&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Programming Language :: Python&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Programming Language :: Python :: 3&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Programming Language :: Python :: 3 :: Only&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Programming Language :: Python :: 3.12&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Programming Language :: Python :: 3.13&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Programming Language :: Python :: 3.14&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><span class=\"s2\">&quot;Topic :: Internet :: WWW/HTTP&quot;</span><span class=\"p\">,</span>\n<span class=\"w\">    </span><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>\n<span class=\"n\">Homepage</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </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\"><span class=\"pre\">MANIFEST.in</span></code> file. To include the templates and static files, create a\nfile <code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls/MANIFEST.in</span></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\"><span class=\"pre\">django-polls/MANIFEST.in</span></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\"><span class=\"pre\">django-polls/docs</span></code> for future\ndocumentation.</p>\n<p>Σημειώστε ότι ο φάκελος <code class=\"docutils literal notranslate\"><span class=\"pre\">docs</span></code> δεν θα συμπεριληφθεί στο package σας εκτός και αν προσθέσετε μερικά αρχεία μέσα. Σε περίπτωση που δεν το γνωρίζατε, πολλά Django apps παρέχουν το δικό τους documentation και online μέσα από ιστοσελίδες όπως η <a class=\"reference external\" href=\"https://readthedocs.org\">readthedocs.org</a>.</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\"><span class=\"pre\">intersphinx_mapping</span></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><span class=\"n\">intersphinx_mapping</span> <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\"><span class=\"pre\">:attr:`django.test.TransactionTestCase.databases`</span></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\"><span class=\"pre\">python</span> <span class=\"pre\">-m</span> <span class=\"pre\">pip</span> <span class=\"pre\">install</span>\n<span class=\"pre\">build</span></code>) and try building your package by running <code class=\"docutils literal notranslate\"><span class=\"pre\">python</span> <span class=\"pre\">-m</span> <span class=\"pre\">build</span></code> inside\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls</span></code>. This creates a directory called <code class=\"docutils literal notranslate\"><span class=\"pre\">dist</span></code> and builds your\nnew package into source and binary formats, <code class=\"docutils literal notranslate\"><span class=\"pre\">django_polls-0.1.tar.gz</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django_polls-0.1-py3-none-any.whl</span></code>.</p></li>\n</ol>\n<p>For more information on packaging, see Python’s <a class=\"reference external\" href=\"https://packaging.python.org/tutorials/packaging-projects/\">Tutorial on Packaging and\nDistributing Projects</a>.</p>\n</section>\n<section id=\"using-your-own-package\">\n<h2>Χρησιμοποιώντας το δικό σας package<a class=\"heading-anchor\" href=\"#using-your-own-package\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Από τη στιγμή που μετακινήσαμε τον φάκελο <code class=\"docutils literal notranslate\"><span class=\"pre\">polls</span></code> έξω από το project, η εφαρμογή μας δεν δουλεύει πλέον, κάτι το οποίο είναι λογικό. Σε αυτή την παράγραφο θα εγκαταστήσουμε την εφαρμογή μας,``django-polls``, σαν ένα (τρίτο) πακέτο.</p>\n<aside class=\"admonition-installing-as-a-user-library admonition\">\n<p class=\"admonition-title\">Εγκατάσταση ως βιβλιοθήκη χρήστη (user library)</p>\n<p>Τα ακόλουθα βήματα εγκαθιστούν το πακέτο <code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls</span></code> ως μια βιβλιοθήκη χρήστη. Αυτό σημαίνει ότι το πακέτο θα εγκατασταθεί στον υπολογιστή για τον συγκεκριμένο χρήστη και όχι γενικά (global) για όλους τους χρήστες του συστήματος. Αυτή η εγκατάσταση έχει πολλά πλεονεκτήματα έναντι της γενικής (global) διότι μπορεί η εφαρμογή να χρησιμοποιηθεί σε συστήματα όπου δεν υπάρχουν δικαιώματα διαχειριστή ή να αποτρέψει την πρόσβαση στην εφαρμογή από άλλους χρήστες ή άλλες υπηρεσίες του συστήματος.</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<span class=\"w\"> </span>-m<span class=\"w\"> </span>pip<span class=\"w\"> </span>install<span class=\"w\"> </span>--user<span class=\"w\"> </span>django-polls/dist/django_polls-0.1.tar.gz\n</code></pre></div>\n</li>\n<li><p>Update <code class=\"docutils literal notranslate\"><span class=\"pre\">mysite/settings.py</span></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><span class=\"n\">INSTALLED_APPS</span> <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\"><span class=\"pre\">mysite/urls.py</span></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><span class=\"n\">urlpatterns</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"n\">path</span><span class=\"p\">(</span><span class=\"s2\">&quot;polls/&quot;</span><span class=\"p\">,</span> <span class=\"n\">include</span><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>Δημοσιεύοντας το app σας<a class=\"heading-anchor\" href=\"#publishing-your-app\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Τώρα που έχουμε μετατρέψει σε package και τεστάρει την εφαρμογή <code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls</span></code>, είναι έτοιμη να διαμοιραστεί στον υπόλοιπο κόσμο! Αν αυτό δεν ήταν κάποιο παράδειγμα, θα μπορούσατε να:</p>\n<ul class=\"simple\">\n<li><p>Στείλετε με email το package σε κάποιον φίλο.</p></li>\n<li><p>Να ανεβάσετε το package στην ιστοσελίδα σας.</p></li>\n<li><p>Post the package on a public repository, such as <a class=\"reference external\" href=\"https://pypi.org/\">the Python Package Index\n(PyPI)</a>. There is <a class=\"reference external\" href=\"https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives\">a good tutorial</a>\nfor doing this.</p></li>\n</ul>\n</section>\n<section id=\"installing-python-packages-with-a-virtual-environment\">\n<h2>Installing Python packages with a virtual environment<a class=\"heading-anchor\" href=\"#installing-python-packages-with-a-virtual-environment\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Earlier, we installed <code class=\"docutils literal notranslate\"><span class=\"pre\">django-polls</span></code> as a user library. This has some\ndisadvantages:</p>\n<ul class=\"simple\">\n<li><p>Η αλλαγή των βιβλιοθηκών χρηστών μπορεί να επηρεάσει άλλο Python software μέσα στο σύστημα σας.</p></li>\n<li><p>Δεν θα είστε σε θέση να τρέξετε πολλαπλές εκδόσεις το ίδιου πακέτου (ή άλλων με το ίδιο όνομα).</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=\"(στη Python έκδοση 3.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":"Η επαναχρησιμοποίηση έχει σημασία","anchor":"reusability-matters","children":[]},{"title":"Το project σας και η επαναχρησιμοποιήσιμη app","anchor":"your-project-and-your-reusable-app","children":[]},{"title":"Εγκαθιστώντας μερικά προαπαιτούμενα","anchor":"installing-some-prerequisites","children":[]},{"title":"Πακετάροντας το app σας","anchor":"packaging-your-app","children":[]},{"title":"Χρησιμοποιώντας το δικό σας package","anchor":"using-your-own-package","children":[]},{"title":"Δημοσιεύοντας το app σας","anchor":"publishing-your-app","children":[]},{"title":"Installing Python packages with a virtual environment","anchor":"installing-python-packages-with-a-virtual-environment","children":[]}],"breadcrumbs":[{"docname":"intro/index","title":"Ξεκινώντας","url":"/el/6.1/intro/"}],"prev":{"docname":"intro/tutorial08","title":"Writing your first Django app, part 8","url":"/el/6.1/intro/tutorial08/"},"next":{"docname":"intro/whatsnext","title":"Τι να διαβάσετε μετά","url":"/el/6.1/intro/whatsnext/"},"formats":{"html":"/el/6.1/intro/reusable-apps/","markdown":"/el/6.1/intro/reusable-apps.md","json":"/el/6.1/intro/reusable-apps.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/intro/reusable-apps.txt","official":"https://docs.djangoproject.com/el/6.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"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}