{"title":"Γράφοντας το πρώτο σας Django app, μέρος 1","version":"5.2","locale":"el","docname":"intro/tutorial01","url":"/el/5.2/intro/tutorial01/","canonical":"https://djangodocs.dev/el/5.2/intro/tutorial01/","summary":"Ο μόνος τρόπος να μάθετε να γράφετε Django apps (εφαρμογές) και γενικά να δουλεύετε με το Django είναι μέσα από παραδείγματα.","html":"<h1>Γράφοντας το πρώτο σας Django app, μέρος 1<a class=\"heading-anchor\" href=\"#writing-your-first-django-app-part-1\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Ο μόνος τρόπος να μάθετε να γράφετε Django apps (εφαρμογές) και γενικά να δουλεύετε με το Django είναι μέσα από παραδείγματα.</p>\n<p>Μέσα από αυτόν τον οδηγό, θα φτιάξουμε παρέα μία απλή εφαρμογή (application) ψηφοφορίας (poll app). Κάθε ερώτηση θα απαρτίζεται από ένα σετ απαντήσεων, από τις οποίες ο χρήστης θα μπορεί να επιλέξει μία κάθε φορά.</p>\n<p>Η εφαρμογή θα αποτελείται από δύο μέρη:</p>\n<ul class=\"simple\">\n<li><p>Ένα κοινό-δημόσιο site που θα επιτρέπει στους χρήστες να βλέπουν τις διαθέσιμες ψηφοφορίες (γκάλοπ, αν προτιμάτε) και να ψηφίζουν.</p></li>\n<li><p>Ένα διαχειριστικό (admin) site το οποίο θα επιτρέπει σε εσάς (που θα είστε ο διαχειριστής) να προσθέτετε νέες, να αλλάζετε ήδη υπάρχουσες αλλά και να διαγράφετε ψηφοφορίες.</p></li>\n</ul>\n<p>Υποθέτουμε ότι έχετε ήδη <a class=\"reference internal\" href=\"/el/5.2/intro/install/\"><span class=\"doc\">εγκαταστήσει το Django</span></a> στον υπολογιστή σας. Μπορείτε να δείτε αν το Django έχει εγκατασταθεί (και αν ναι, ποια έκδοση διαθέτετε) πληκτρολογώντας στην κονσόλα (γραμμή εντολών):</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-0-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><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><span class=\"gp\">$ </span>python -m django --version\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-0-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py -m django --version\n</code></pre></div></div></div>\n<p>Αν το Django είναι εγκατεστημένο, θα δείτε την έκδοση του. Αν δεν είναι, θα δείτε ένα σφάλμα λέγοντας σας ότι “δεν υπάρχει κάποιο module με το όνομα django” (no module named django).</p>\n<p>This tutorial is written for Django 5.2, which supports Python 3.10 and\nlater. If the Django version doesn’t match, you can refer to the tutorial for\nyour version of Django by using the version switcher at the bottom right corner\nof this page, or update Django to the newest version. If you’re using an older\nversion of Python, check <a class=\"reference internal\" href=\"/el/5.2/faq/install/#faq-python-version-support\"><span class=\"std std-ref\">Ποια έκδοση της Python να χρησιμοποιήσω με το Django;</span></a> to find a compatible\nversion of Django.</p>\n<aside class=\"admonition-where-to-get-help admonition\" role=\"note\">\n<p class=\"admonition-title\">Που να ψάξετε για βοήθεια</p>\n<p>If you’re having trouble going through this tutorial, please head over to\nthe <a class=\"reference internal\" href=\"/el/5.2/faq/help/\"><span class=\"doc\">Getting Help</span></a> section of the FAQ.</p>\n</aside>\n<section id=\"creating-a-project\">\n<h2>Δημιουργία project<a class=\"heading-anchor\" href=\"#creating-a-project\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Αν αυτή είναι η πρώτη φορά που χρησιμοποιείτε το Django, θα χρειαστεί να ρυθμίσετε κάποια πράγματα στην αρχή. Θυμηθείτε ότι οι σωστές βάσεις δημιουργούν σταθερά σπίτια. Πιο συγκεκριμένα, θα χρειαστεί να τρέξετε μια Django εντολή η οποία θα δημιουργήσει αυτόματα ένα Django <a class=\"reference internal\" href=\"/el/5.2/glossary/#term-project\"><span class=\"xref std std-term\">project</span></a> – το οποίο δεν είναι τίποτε άλλο παρά ένας φάκελος (μια συλλογή από ρυθμίσεις, αν θέλετε) που περιέχει διάφορα αρχεία, όπως ρυθμίσεις της βάσης δεδομένων, διάφορες επιλογές του Django και ρυθμίσεις που αφορούν το application σας. Αν μπερδευτήκατε, μην ανησυχείτε, θα διαλευκανθούν όλα καθώς προχωράμε στον οδηγό.</p>\n<p>From the command line, <code class=\"docutils literal notranslate\">cd</code> into a directory where you’d like to store your\ncode and create a new directory named <code class=\"docutils literal notranslate\">djangotutorial</code>. (This directory name\ndoesn’t matter to Django; you can rename it to anything you like.)</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-1-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><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><span class=\"gp\">$ </span>mkdir djangotutorial\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-1-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> <span class=\"k\">mkdir</span> djangotutorial\n</code></pre></div></div></div>\n<p>Then, run the following command to bootstrap a new Django project:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-2-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><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><span class=\"gp\">$ </span>django-admin startproject mysite djangotutorial\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-2-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> django-admin startproject mysite djangotutorial\n</code></pre></div></div></div>\n<p>This will create a project called <code class=\"docutils literal notranslate\">mysite</code> inside the <code class=\"docutils literal notranslate\">djangotutorial</code>\ndirectory. If it didn’t work, see <a class=\"reference internal\" href=\"/el/5.2/faq/troubleshooting/#troubleshooting-django-admin\"><span class=\"std std-ref\">Προβλήματα στην εκτέλεση της εντολής django-admin</span></a>.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Σημείωση</p>\n<p>Θα πρέπει να δώσετε ιδιαίτερη προσοχή στην ονομασία του project σας, προσέχοντας να μην το ονομάσετε με δεσμευμένες λέξεις που χρησιμοποιεί η Python ή το Django. Πιο συγκεκριμένα, θα πρέπει να αποφεύγετε ονομασίες όπως <code class=\"docutils literal notranslate\">django</code> (κάτι το οποίο θα έρθει σε σύγκρουση με το ίδιο το Django) ή <code class=\"docutils literal notranslate\">test</code> (το οποίο θα έρθει σε σύγκρουση με το προεγκατεστημένο πακέτο της Python).</p>\n</aside>\n<p>Let’s look at what <a class=\"reference internal\" href=\"/el/5.2/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\">startproject</code></a> created:</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</code></pre></div>\n<p>Αυτά τα αρχεία είναι:</p>\n<ul class=\"simple\">\n<li><p><code class=\"file docutils literal notranslate\">manage.py</code>: Αυτό το αρχείο αποτελεί εντολή (κονσόλας) την οποία μπορείτε να χρησιμοποιήσετε (και θα το κάνετε) για να αλληλεπιδράτε με το project σας για διάφορους λόγους (π.χ δημιουργία πινάκων στη database, εκκίνηση του προ-εγκατεστημένου server κλπ). Μπορείτε να διαβάσετε όλες τις λεπτομέρειες σχετικά με το αρχείο <code class=\"file docutils literal notranslate\">manage.py</code> στο <a class=\"reference internal\" href=\"/el/5.2/ref/django-admin/\"><span class=\"doc\">django-admin and manage.py</span></a>.</p></li>\n<li><p><code class=\"file docutils literal notranslate\">mysite/</code>: A directory that is the actual Python package for your\nproject. Its name is the Python package name you’ll need to use to import\nanything inside it (e.g. <code class=\"docutils literal notranslate\">mysite.urls</code>).</p></li>\n<li><p><code class=\"file docutils literal notranslate\">mysite/__init__.py</code>: Ένα κενό αρχείο που λέει στην Python ότι αυτός ο φάκελος θα πρέπει να θεωρηθεί ως Python package. Αν είστε καινούργιος στην Python, διαβάστε <a class=\"reference external\" href=\"https://docs.python.org/3/tutorial/modules.html#tut-packages\" title=\"(στη Python έκδοση 3.14)\"><span class=\"xref std std-ref\">περισσότερα σχετικά με τα packages</span></a> στην επίσημη ιστοσελίδα της Python.</p></li>\n<li><p><code class=\"file docutils literal notranslate\">mysite/settings.py</code>: Ένα αρχείο που κρατά όλες τις ρυθμίσεις/παραμέτρους για αυτό το Django project (είναι η καρδιά ενός project).  Το άρθρο <a class=\"reference internal\" href=\"/el/5.2/topics/settings/\"><span class=\"doc\">Django settings</span></a> θα σας εξηγήσει όλα όσα χρειάζεστε σχετικά με το πως δουλεύουν οι ρυθμίσεις αυτές.</p></li>\n<li><p><code class=\"file docutils literal notranslate\">mysite/urls.py</code>: Το αρχείο αυτό κρατά τους ορισμούς των URLs για αυτό το project. Με άλλα λόγια είναι ένας «πίνακας περιεχομένων» του Django site σας. Μπορείτε να διαβάστε περισσότερα για τα URLs στο άρθρο <a class=\"reference internal\" href=\"/el/5.2/topics/http/urls/\"><span class=\"doc\">URL dispatcher</span></a>.</p></li>\n<li><p><code class=\"file docutils literal notranslate\">mysite/asgi.py</code>: An entry-point for ASGI-compatible web servers to\nserve your project. See <a class=\"reference internal\" href=\"/el/5.2/howto/deployment/asgi/\"><span class=\"doc\">How to deploy with ASGI</span></a> for more details.</p></li>\n<li><p><code class=\"file docutils literal notranslate\">mysite/wsgi.py</code>: Αυτό το αρχείο αποτελεί ένα σημείο εισόδου για τους Web servers οι οποίοι είναι συμβατοί με το WSGI specification. Δείτε περισσότερα στο άρθρο <a class=\"reference internal\" href=\"/el/5.2/howto/deployment/wsgi/\"><span class=\"doc\">πως να δουλέψω με το WSGI</span></a> για περισσότερες λεπτομέρειες.</p></li>\n</ul>\n</section>\n<section id=\"the-development-server\">\n<h2>Ο development server<a class=\"heading-anchor\" href=\"#the-development-server\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Let’s verify your Django project works. Change into the <code class=\"file docutils literal notranslate\">djangotutorial</code>\ndirectory, if you haven’t already, and run the following commands:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-3-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><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><span class=\"gp\">$ </span>python manage.py runserver\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-3-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py manage.py runserver\n</code></pre></div></div></div>\n<p>Θα δείτε την ακόλουθη έξοδο, στη κονσόλα:</p>\n<pre class=\"literal-block\">Performing system checks...\n\nSystem check identified no issues (0 silenced).\n\nYou have unapplied migrations; your app may not work properly until they are applied.\nRun 'python manage.py migrate' to apply them.\n\n03 Οκτωβρίου 2026 - 15:50:53\nDjango version 5.2, using settings 'mysite.settings'\nStarting development server at <a class=\"reference external\" href=\"http://127.0.0.1:8000/\">http://127.0.0.1:8000/</a>\nQuit the server with CONTROL-C.\n\nWARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.\nFor more information on production servers see: <a class=\"reference external\" href=\"https://docs.djangoproject.com/en/\">https://docs.djangoproject.com/en/</a>5.2/howto/deployment/</pre>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Σημείωση</p>\n<p>Αγνοήστε την προειδοποίηση (warning) περί unapplied migrations προς το παρόν. Θα ασχοληθούμε με αυτό σε λίγο (αφορά την βάση δεδομένων).</p>\n</aside>\n<p>Now that the server’s running, visit <a class=\"reference external\" href=\"http://127.0.0.1:8000/\">http://127.0.0.1:8000/</a> with your web\nbrowser. You’ll see a «Congratulations!» page, with a rocket taking off.\nIt worked!</p>\n<p>You’ve started the Django development server, a lightweight web server written\npurely in Python. We’ve included this with Django so you can develop things\nrapidly, without having to deal with configuring a production server – such as\nApache – until you’re ready for production.</p>\n<p>Now’s a good time to note: <strong>don’t</strong> use this server in anything resembling a\nproduction environment. It’s intended only for use while developing. (We’re in\nthe business of making web frameworks, not web servers.)</p>\n<p>(To serve the site on a different port, see the <a class=\"reference internal\" href=\"/el/5.2/ref/django-admin/#django-admin-runserver\"><code class=\"xref std std-djadmin docutils literal notranslate\">runserver</code></a> reference.)</p>\n<aside class=\"admonition-automatic-reloading-of-djadmin-runserver admonition\" role=\"note\">\n<p class=\"admonition-title\">Αυτόματη ανανέωση του <a class=\"reference internal\" href=\"/el/5.2/ref/django-admin/#django-admin-runserver\"><code class=\"xref std std-djadmin docutils literal notranslate\">runserver</code></a></p>\n<p>Ο development server ανανεώνεται (reloads) αυτόματα κάθε φορά που αποθηκεύετε ή αλλάζετε κάποιο αρχείο (φυσικά μέσα στο project σας). Με αυτό τον τρόπο δεν χρειάζεται να κάνετε χειροκίνητα το reload του server για να δεχτεί τυχόν αλλαγές που πραγματοποιήθηκαν. Ωστόσο, υπάρχουν περιπτώσεις που ο server δεν ανανεώνεται αυτόματα, όπως στην προσθήκη ή αφαίρεση κάποιου αρχείου. Εκεί πρέπει να γίνει χειροκίνητα η επαναφόρτωση του server.</p>\n</aside>\n</section>\n<section id=\"creating-the-polls-app\">\n<h2>Δημιουργώντας το app ψηφοφορίας<a class=\"heading-anchor\" href=\"#creating-the-polls-app\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Τώρα που το περιβάλλον εργασίας σας – το «project» – είναι έτοιμο, μπορείτε να ξεκινήσετε να δημιουργείτε.</p>\n<p>Κάθε application που γράφετε στο Django αποτελείται από ένα Python package (ένας φάκελος που περιέχει το αρχείο <code class=\"docutils literal notranslate\">__init__.py</code>) το οποίο πρέπει να ακολουθεί ορισμένους κανόνες. Για άλλη μια φορά, το Django σας παρέχει την ανάλογη εντολή για να δημιουργήσετε αυτόματα τη δομή αυτού του φακέλου (Python package) ούτως ώστε να επικεντρωθείτε στο να γράψετε κώδικα παρά στο να δημιουργείτε φακέλους και υποφακέλους.</p>\n<aside class=\"admonition-projects-vs-apps admonition\" role=\"note\">\n<p class=\"admonition-title\">Projects vs. apps</p>\n<p>What’s the difference between a project and an app? An app is a web\napplication that does something – e.g., a blog system, a database of\npublic records or a small poll app. A project is a collection of\nconfiguration and apps for a particular website. A project can contain\nmultiple apps. An app can be in multiple projects.</p>\n</aside>\n<p>Your apps can live anywhere in your <a class=\"reference external\" href=\"https://docs.python.org/3/tutorial/modules.html#tut-searchpath\" title=\"(στη Python έκδοση 3.14)\"><span class=\"xref std std-ref\">Python path</span></a>. In\nthis tutorial, we’ll create our poll app inside the <code class=\"docutils literal notranslate\">djangotutorial</code> folder.</p>\n<p>Για να δημιουργήσετε το app, σιγουρευτείτε ότι βρίσκεστε στο ίδιο επίπεδο με το αρχείο <code class=\"file docutils literal notranslate\">manage.py</code> και πληκτρολογήστε την εντολή:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-4-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><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><span class=\"gp\">$ </span>python manage.py startapp polls\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-4-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py manage.py startapp polls\n</code></pre></div></div></div>\n<p>That’ll create a directory <code class=\"file docutils literal notranslate\">polls</code>, which is laid out 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>polls/\n    __init__.py\n    admin.py\n    apps.py\n    migrations/\n        __init__.py\n    models.py\n    tests.py\n    views.py\n</code></pre></div>\n<p>Αυτή η δομή θα εσωκλείει ολόκληρη την εφαρμογή μας.</p>\n</section>\n<section id=\"write-your-first-view\">\n<h2>Γράφοντας το πρώτο σας view<a class=\"heading-anchor\" href=\"#write-your-first-view\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Ας γράψουμε το πρώτο μας view. Ανοίξτε το αρχείο <code class=\"docutils literal notranslate\">polls/views.py</code> και γράψτε τον ακόλουθο Python κώδικα:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">polls/views.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.http</span> <span class=\"kn\">import</span> HttpResponse\n\n\n<span class=\"k\">def</span> <span class=\"nf\">index</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s2\">&quot;Hello, world. You&#39;re at the polls index.&quot;</span><span class=\"p\">)</span>\n</code></pre></figure>\n<p>This is the most basic view possible in Django. To access it in a browser, we\nneed to map it to a URL - and for this we need to define a URL configuration,\nor «URLconf» for short. These URL configurations are defined inside each\nDjango app, and they are Python files named <code class=\"docutils literal notranslate\">urls.py</code>.</p>\n<p>To define a URLconf for the <code class=\"docutils literal notranslate\">polls</code> app, create a file <code class=\"docutils literal notranslate\">polls/urls.py</code>\nwith the following content:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">polls/urls.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.urls</span> <span class=\"kn\">import</span> path\n\n<span class=\"kn\">from</span> <span class=\"nn\">.</span> <span class=\"kn\">import</span> views\n\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span> views<span class=\"o\">.</span>index<span class=\"p\">,</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;index&quot;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></figure>\n<p>Your app directory should now look like:</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>polls/\n    __init__.py\n    admin.py\n    apps.py\n    migrations/\n        __init__.py\n    models.py\n    tests.py\n    urls.py\n    views.py\n</code></pre></div>\n<p>The next step is to configure the root URLconf in the <code class=\"docutils literal notranslate\">mysite</code> project to\ninclude the URLconf defined in <code class=\"docutils literal notranslate\">polls.urls</code>. To do this, add an import for\n<code class=\"docutils literal notranslate\">django.urls.include</code> in <code class=\"docutils literal notranslate\">mysite/urls.py</code> and insert an\n<a class=\"reference internal\" href=\"/el/5.2/ref/urls/#django.urls.include\" title=\"django.urls.include\"><code class=\"xref py py-func docutils literal notranslate\">include()</code></a> in the <code class=\"docutils literal notranslate\">urlpatterns</code> list, so you have:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">mysite/urls.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.contrib</span> <span class=\"kn\">import</span> admin\n<span class=\"kn\">from</span> <span class=\"nn\">django.urls</span> <span class=\"kn\">import</span> include<span class=\"p\">,</span> path\n\nurlpatterns <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;polls.urls&quot;</span><span class=\"p\">)),</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;admin/&quot;</span><span class=\"p\">,</span> admin<span class=\"o\">.</span>site<span class=\"o\">.</span>urls<span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></figure>\n<p>The <a class=\"reference internal\" href=\"/el/5.2/ref/urls/#django.urls.path\" title=\"django.urls.path\"><code class=\"xref py py-func docutils literal notranslate\">path()</code></a> function expects at least two arguments:\n<code class=\"docutils literal notranslate\">route</code> and <code class=\"docutils literal notranslate\">view</code>.\nThe <a class=\"reference internal\" href=\"/el/5.2/ref/urls/#django.urls.include\" title=\"django.urls.include\"><code class=\"xref py py-func docutils literal notranslate\">include()</code></a> function allows referencing other URLconfs.\nWhenever Django encounters <a class=\"reference internal\" href=\"/el/5.2/ref/urls/#django.urls.include\" title=\"django.urls.include\"><code class=\"xref py py-func docutils literal notranslate\">include()</code></a>, it chops off whatever\npart of the URL matched up to that point and sends the remaining string to the\nincluded URLconf for further processing.</p>\n<p>The idea behind <a class=\"reference internal\" href=\"/el/5.2/ref/urls/#django.urls.include\" title=\"django.urls.include\"><code class=\"xref py py-func docutils literal notranslate\">include()</code></a> is to make it easy to\nplug-and-play URLs. Since polls are in their own URLconf\n(<code class=\"docutils literal notranslate\">polls/urls.py</code>), they can be placed under «/polls/», or under\n«/fun_polls/», or under «/content/polls/», or any other path root, and the\napp will still work.</p>\n<aside class=\"admonition-when-to-use-func-django-urls-include admonition\" role=\"note\">\n<p class=\"admonition-title\">When to use <a class=\"reference internal\" href=\"/el/5.2/ref/urls/#django.urls.include\" title=\"django.urls.include\"><code class=\"xref py py-func docutils literal notranslate\">include()</code></a></p>\n<p>You should always use <code class=\"docutils literal notranslate\">include()</code> when you include other URL patterns.\nThe only exception is <code class=\"docutils literal notranslate\">admin.site.urls</code>, which is a pre-built URLconf\nprovided by Django for the default admin site.</p>\n</aside>\n<p>You have now wired an <code class=\"docutils literal notranslate\">index</code> view into the URLconf. Verify it’s working with\nthe following command:</p>\n<div class=\"console\" data-console><div class=\"console-panel\" data-platform=\"unix\"><p class=\"console-label\" id=\"console-5-unix-label\">Linux / macOS</p><div class=\"code-block\" data-language=\"console\"><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><span class=\"gp\">$ </span>python manage.py runserver\n</code></pre></div>\n</div><div class=\"console-panel\" data-platform=\"windows\"><p class=\"console-label\" id=\"console-5-windows-label\">Windows</p><div class=\"code-block\" data-language=\"doscon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Windows</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=\"Windows shell\"><code><span class=\"gp\">...\\&gt;</span> py manage.py runserver\n</code></pre></div></div></div>\n<p>Επισκεφτείτε την σελίδα <a class=\"reference external\" href=\"http://localhost:8000/polls/\">http://localhost:8000/polls/</a> με τον browser σας και θα πρέπει να δείτε το κείμενο «<em>Hello, world. You’re at the polls index.</em>», το οποίο γράψαμε στην <code class=\"docutils literal notranslate\">index</code> view.</p>\n<aside class=\"admonition-page-not-found admonition\" role=\"note\">\n<p class=\"admonition-title\">Page not found?</p>\n<p>If you get an error page here, check that you’re going to\n<a class=\"reference external\" href=\"http://localhost:8000/polls/\">http://localhost:8000/polls/</a> and not <a class=\"reference external\" href=\"http://localhost:8000/\">http://localhost:8000/</a>.</p>\n</aside>\n<p>Όταν αισθανθείτε άνετα με αυτό τον οδηγό και με τη λειτουργία της Web request-Web response διαδικασίας μπορείτε να συνεχίσετε στο <a class=\"reference internal\" href=\"/el/5.2/intro/tutorial02/\"><span class=\"doc\">δεύτερο μέρος αυτού του οδηγού</span></a> για να εργαστείτε με τη βάση δεδομένων.</p>\n</section>","rootId":"writing-your-first-django-app-part-1","toc":[{"title":"Δημιουργία project","anchor":"creating-a-project","children":[]},{"title":"Ο development server","anchor":"the-development-server","children":[]},{"title":"Δημιουργώντας το app ψηφοφορίας","anchor":"creating-the-polls-app","children":[]},{"title":"Γράφοντας το πρώτο σας view","anchor":"write-your-first-view","children":[]}],"breadcrumbs":[{"docname":"intro/index","title":"Ξεκινώντας","url":"/el/5.2/intro/"}],"prev":{"docname":"intro/install","title":"Οδηγός γρήγορης εγκατάστασης","url":"/el/5.2/intro/install/"},"next":{"docname":"intro/tutorial02","title":"Γράφοντας το πρώτο σας Django app, μέρος 2","url":"/el/5.2/intro/tutorial02/"},"formats":{"html":"/el/5.2/intro/tutorial01/","markdown":"/el/5.2/intro/tutorial01.md","json":"/el/5.2/intro/tutorial01.json"},"source":"https://github.com/django/django/blob/stable/5.2.x/docs/intro/tutorial01.txt","official":"https://docs.djangoproject.com/el/5.2/intro/tutorial01/","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"]}