---
title: "Scríobh do chéad aip Django, cuid 1"
version: 6.1
locale: ga
source: https://docs.djangoproject.com/ga/6.1/intro/tutorial01/
canonical: https://djangodocs.dev/ga/6.1/intro/tutorial01/
---
# Scríobh do chéad aip Django, cuid 1

Foghlaimímis trí shampla.

Le linn an teagaisc seo, beimid ag siúl leat trí bhunfheidhmchlár vótaíochta a chruthú.

Beidh dhá chuid ann:

- Suíomh poiblí a ligeann do dhaoine féachaint ar na pobalbhreitheanna agus vótáil iontu.
- Suíomh riaracháin a ligeann duit pobalbhreitheanna a chur leis, a athrú agus a scriosadh.

Glacfaimid leis go bhfuil :d oc: Django suiteáilte \</intro/install\> agat cheana féin. Is féidir leat a rá go bhfuil Django suiteáilte agus cén leagan tríd an ordú seo a leanas a rith i leid bhlaosc (arna léiriú ag an réimír $):

```console
$ python -m django --version
```

*Windows*

```doscon
...\> py -m django --version
```

Má tá Django suiteáilte, ba chóir duit an leagan de do shuiteáil a fheiceáil. Mura bhfuil, gheobhaidh tú earráid ag insint "Níl modúl darb ainm django".

This tutorial is written for Django 6.1, which supports Python 3.12 and
later. If the Django version doesn't match, you can refer to the tutorial for
your version of Django by using the version switcher at the bottom right corner
of this page, or update Django to the newest version. If you're using an older
version of Python, check [Cén leagan Python is féidir liom a úsáid le Django?](/ga/6.1/faq/install/#faq-python-version-support) to find a compatible
version of Django.

> **Cá háit le cabhair a fháil:**
>
> Má tá deacracht agat dul tríd an rang teagaisc seo, téigh ar aghaidh chuig an rannán :d oc:'Getting Help\</faq/help\>' den rannán Ceisteanna Coitianta.

## Tionscadal a chruthú

Más é seo do chéad uair ag baint úsáide as Django, beidh ort aire a thabhairt do roinnt thus tosaigh. Eadhon, beidh ort roinnt cód a ghiniúint go huathoibríoch a bhunaíonn Django: téarma: 'tionscadal' - bailiúchán socruithe le haghaidh sampla de Django, lena n-áirítear cumraíocht bunachar sonraí, roghanna Django-sonrach agus socruithe a bhaineann go sonrach le feidhmchlár.

From the command line, `cd` into a directory where you'd like to store your
code and run the following command to bootstrap a new Django project:

```console
$ django-admin startproject mysite djangotutorial
```

*Windows*

```doscon
...\> django-admin startproject mysite djangotutorial
```

This will create a directory `djangotutorial` with a project called
`mysite` inside. The directory name doesn't matter to Django; you can rename
it to anything you like. If it didn't work, see
[Fadhbanna ag rith ''django-admin''](/ga/6.1/faq/troubleshooting/#troubleshooting-django-admin).

> **Note**
>
> Beidh ort tionscadail a ainmniú tar éis comhpháirteanna Python nó Django tógtha isteach. Go háirithe, ciallaíonn sé seo gur chóir duit ainmneacha mar `django` (a thiocfaidh salach ar Django féin) nó `test` (a thagann salach ar phacáiste Python ionsuite) a sheachaint.

Breathnaímis ar an méid a chruthaigh :d jadmin:'startproject':

```text
djangotutorial/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py
```

Is iad seo a leanas na comhaid seo:

- `manage.py`: A command-line utility that lets you interact with this
  Django project in various ways. You can read all the details about
  `manage.py` in [django-admin agus manage.py](/ga/6.1/ref/django-admin/).
- : Eolaire arb é an pacáiste Python iarbhír do do thionscadal. Is é an t-ainm an t-ainm pacáiste Python a chaithfidh tú a úsáid chun aon rud a allmhairiú laistigh de (m.sh. `mysite.urls`).
- `mysite/__init__.py`: Comhad folamh a insíonn do Python gur chóir an t-eolaire seo a mheas mar phacáiste Python. Más tosaitheoir Python tú, léigh :ref:'more about packages\<tut-packages\>' sna docs oifigiúla Python.
- `mysite/settings.py`: Settings/configuration for this Django
  project. [Django settings](/ga/6.1/topics/settings/) will tell you all about how settings
  work.
- `mysite/urls.py`: The URL declarations for this Django project; a
  "table of contents" of your Django-powered site. You can read more about
  URLs in [URL dispatcher](/ga/6.1/topics/http/urls/).
- `mysite/asgi.py`: Pointe iontrála do fhreastalaithe gréasáin atá comhoiriúnach le ASGI chun freastal ar do thionscadal. Féach :d oc:/howto/deployment/asgi/index le haghaidh tuilleadh sonraí.
- `mysite/wsgi.py`: : Pointe iontrála le haghaidh freastalaithe gréasáin atá comhoiriúnach le WSGI chun freastal ar do thionscadal. Féach [Conas a imscaradh le WSGI](/ga/6.1/howto/deployment/wsgi/) le haghaidh tuilleadh sonraí.

## An freastalaí forbartha

A ligean ar fhíorú do oibreacha tionscadal Django. Athraigh isteach sa chomhad:djangotutorial eolaire, mura bhfuil tú cheana féin, agus rith na horduithe seo a leanas:

```console
$ python manage.py runserver
```

*Windows*

```doscon
...\> py manage.py runserver
```

Feicfidh tú an t-aschur seo a leanas ar an líne ordaithe:

```
Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are
applied. Run 'python manage.py migrate' to apply them.

Lún 11, 2026 - 15:50:53
Django version 6.1, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/6.1/howto/deployment/
```

> **Note**
>
> Déan neamhaird den rabhadh faoi imirce bunachar sonraí neamhfheidhmithe anois; Déileálfaimid leis an mbunachar sonraí go luath.

Anois go bhfuil an freastalaí ag rith, tabhair cuairt <http://127.0.0.1:8000/> le do bhrabhsálaí gréasáin. Feicfidh tú "Comhghairdeas!" leathanach, le roicéad ag éirí as. D'oibrigh sé!

Thosaigh tú an freastalaí forbartha Django, freastalaí gréasáin éadrom scríofa i Python amháin. Táimid tar éis é seo a chur san áireamh le Django ionas gur féidir leat rudaí a fhorbairt go tapa, gan déileáil le freastalaí táirgeachta a chumrú - mar shampla Apache - go dtí go mbeidh tú réidh le táirgeadh.

Is dea-am é anois le tabhairt faoi deara: **ná** úsáid an freastalaí seo in aon rud atá cosúil le timpeallacht táirgthe. Níl sé beartaithe ach le húsáid agus é ag forbairt. (Táimid i mbun creataí gréasáin a dhéanamh, ní freastalaithe gréasáin.)

(Chun freastal ar an suíomh ar phort eile, féach an tagairt :d jadmin:runserver.)

> **Athluchtú uathoibríoch :d jadmin: 'runserver'**
>
> Athluchtaíonn an freastalaí forbartha cód Python go huathoibríoch do gach iarratas de réir mar is gá. Ní gá duit an freastalaí a atosú chun athruithe cóid a chur i bhfeidhm. Mar sin féin, ní spreagann roinnt gníomhartha cosúil le comhaid a chur leis atosú, mar sin beidh ort an freastalaí a atosú sna cásanna seo.

## Cruthú an aip vótaíochta

Anois go bhfuil do thimpeallacht -- "tionscadal" -- ar bun, tá tú ar tí tosú ag déanamh oibre.

Is éard atá i ngach feidhmchlár a scríobhann tú i Django pacáiste Python a leanann coinbhinsiún áirithe. Tagann Django le fóntais a ghineann struchtúr bunúsach eolaire app go huathoibríoch, ionas gur féidir leat díriú ar chód scríbhneoireachta seachas eolairí a chruthú.

> **Tionscadail vs apps**
>
> Cad é an difríocht idir tionscadal agus aip? Is feidhmchlár gréasáin é aip a dhéanann rud éigin -- m.sh., córas blag, bunachar sonraí de thaifid phoiblí nó aip bheag vótaíochta. Is éard is tionscadal ann ná bailiúchán cumraíochta agus feidhmchlár do shuíomh gréasáin ar leith. Is féidir aipeanna éagsúla a bheith i dtionscadal. Is féidir le app a bheith i dtionscadail éagsúla.

Is féidir le d’aipeanna maireachtáil áit ar bith i do [Python path](https://docs.python.org/3/tutorial/modules.html#tut-searchpath). Sa rang teagaisc seo, cruthóimid ár n-aip vótaíochta laistigh den fhillteán `djangotutorial`.

Chun d'aip a chruthú, cinntigh go bhfuil tú san eolaire céanna le `manage.py` agus clóscríobh an t-ordú seo:

```console
$ python manage.py startapp polls
```

*Windows*

```doscon
...\> py manage.py startapp polls
```

Cruthóidh sé sin eolaire `polls`, atá leagtha amach mar seo:

```text
polls/
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    views.py
```

Beidh an feidhmchlár vótaíochta sa struchtúr eolaire seo.

## Scríobh do chéad amharc

Scríobhaimis an chéad amharc. Oscail an comhad `polls/views.py` agus cuir an cód Python seo a leanas ann:

*`polls/views.py`*

```python
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")
```

Is é seo an dearcadh is bunúsaí is féidir i Django. Chun rochtain a fháil air i mbrabhsálaí, ní mór dúinn é a mhapáil chuig URL - agus chuige seo ní mór dúinn cumraíocht URL, nó "URLconf" a shainiú go gairid. Sainmhínítear na cumraíochtaí URL seo taobh istigh de gach feidhmchlár Django, agus is comhaid Python iad darb ainm `urls.py`.

Chun URLconf a shainmhíniú don aip `polls`, cruthaigh comhad `polls/urls.py` leis an ábhar seo a leanas:

*`polls/urls.py`*

```python
from django.urls import path

from . import views

urlpatterns = [
    path("", views.index, name="index"),
]
```

Ba cheart go mbeadh cuma ar do eolaire feidhmchlár anois:

```text
polls/
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    urls.py
    views.py
```

The next step is to configure the root URLconf in the `mysite` project to
include the URLconf defined in `polls.urls`. To do this, add an import for
`django.urls.include` in `mysite/urls.py` and insert an
[`include()`](/ga/6.1/ref/urls/#django.urls.include) in the `urlpatterns` list, so you have:

*`mysite/urls.py`*

```python
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("polls/", include("polls.urls")),
    path("admin/", admin.site.urls),
]
```

The [`path()`](/ga/6.1/ref/urls/#django.urls.path) function expects at least two arguments:
`route` and `view`.
The [`include()`](/ga/6.1/ref/urls/#django.urls.include) function allows referencing other URLconfs.
Whenever Django encounters [`include()`](/ga/6.1/ref/urls/#django.urls.include), it chops off whatever
part of the URL matched up to that point and sends the remaining string to the
included URLconf for further processing.

Is é an smaoineamh taobh thiar de [`include()`](/ga/6.1/ref/urls/#django.urls.include) é a dhéanamh éasca URLanna plug-and-play. Ós rud é go bhfuil pobalbhreith ina URLconf féin (\`\` pobalbhreith/urls.py\`\`), is féidir iad a chur faoi "/polls/", nó faoi "/fun\_polls/", nó faoi "/content/polls/", nó aon fréimhe cosán eile, agus beidh an app fós ag obair.

> **When to use include()**
>
> Ba chóir duit `include()` a úsáid i gcónaí nuair a chuireann tú patrúin URL eile san áireamh. Is é an t-aon eisceacht ná `admin.site.urls`, ar URLconf réamhthógtha é a sholáthraíonn Django don suíomh riaracháin réamhshocraithe.

Tá amharc `index` sreangaithe agat anois sa URLconf. Fíoraigh go bhfuil sé ag obair leis an ordú seo a leanas:

```console
$ python manage.py runserver
```

*Windows*

```doscon
...\> py manage.py runserver
```

Téigh go <http://localhost:8000/polls/> i do bhrabhsálaí, agus ba cheart duit an téacs "*Dia duit, world. Tá tú ag an innéacs pobalbhreithe.*" a fheiceáil, a shainigh tú sa radharc `innéacs` .

> **Ní bhfuarthas an leathanach?**
>
> Má fhaigheann tú leathanach earráide anseo, seiceáil go bhfuil tú ag dul chuig <http://localhost:8000/polls/> agus ní <http://localhost:8000/>.

Nuair atá tú compordach leis an mbunsreabhadh iarratais agus freagartha, léigh [cuid 2 den rang teagaisc seo](/ga/6.1/intro/tutorial02/) chun tosú ag obair leis an mbunachar sonraí.
