---
title: "Γράφοντας το πρώτο σας Django app, μέρος 6"
version: 5.0
locale: el
source: https://docs.djangoproject.com/el/5.0/intro/tutorial06/
canonical: https://djangodocs.dev/el/5.0/intro/tutorial06/
---
# Γράφοντας το πρώτο σας Django app, μέρος 6

This tutorial begins where [Tutorial 5](/el/5.0/intro/tutorial05/) left off.
We’ve built a tested web-poll application, and we’ll now add a stylesheet and
an image.

Πέρα από την HTML που παράγεται από τον server, τα web applications, σε γενικές γραμμές, χρειάζονται να κάνουν serve και πρόσθετα αρχεία — όπως εικόνες, γραμματοσειρές, JavaScript αρχεία, CSS κλπ — αρχεία απαραίτητα ούτως ώστε μια πλήρης ιστοσελίδα να γίνει render. Στο Django, αναφερόμαστε σε αυτά τα αρχεία ως «static files».

For small projects, this isn’t a big deal, because you can keep the static
files somewhere your web server can find it. However, in bigger projects –
especially those comprised of multiple apps – dealing with the multiple sets
of static files provided by each application starts to get tricky.

Αυτό ακριβώς κάνει το `django.contrib.staticfiles`: συγκεντρώνει όλα τα static files από κάθε εφαρμογή σας (και οποιοδήποτε άλλο μέρος εσείς καθορίσετε) σε μια τοποθεσία (που εσείς πάλι καθορίζετε) από την οποία μπορούν εύκολα να γίνουν served σε παραγωγικό περιβάλλον (production).

> **Που να ψάξετε για βοήθεια**
>
> If you’re having trouble going through this tutorial, please head over to
> the [Getting Help](/el/5.0/faq/help/) section of the FAQ.

## Προσαρμογή της εμφάνισης της *εφαρμογής* σας

Πρώτα, δημιουργήστε ένα φάκελο με το όνομα `static` μέσα στο φάκελο `polls` (μέσα, δηλαδή, στην εφαρμογή σας). Το Django θα ψάξει για τυχόν static files μέσα εκεί, ομοίως όπως ψάχνει για templates μέσα στο φάκελο `polls/templates/`.

Η ρύθμιση του Django [`STATICFILES_FINDERS`](/el/5.0/ref/settings/#std-setting-STATICFILES_FINDERS) περιέχει μια λίστα από finders οι οποίοι γνωρίζουν πως να βρίσκουν τα static files από διάφορα μέρη. Μια από τις προεπιλογές είναι η `AppDirectoriesFinder` η οποία κοιτάζει να βρει έναν υπό-φάκελο με το όνομα «static» σε κάθε εφαρμογή η οποία συγκαταλέγεται στη λίστα της ρύθμισης [`INSTALLED_APPS`](/el/5.0/ref/settings/#std-setting-INSTALLED_APPS) (όπως ο υπό-φάκελος που μόλις δημιουργήσαμε μέσα στην εφαρμογή `polls`). Το admin site χρησιμοποιεί την ίδια αρχιτεκτονική φακέλων για τα δικά του static files.

Within the `static` directory you have just created, create another directory
called `polls` and within that create a file called `style.css`. In other
words, your stylesheet should be at `polls/static/polls/style.css`. Because
of how the `AppDirectoriesFinder` staticfile finder works, you can refer to
this static file in Django as `polls/style.css`, similar to how you reference
the path for templates.

> **Static file namespacing**
>
> Just like templates, we *might* be able to get away with putting our static
> files directly in `polls/static` (rather than creating another `polls`
> subdirectory), but it would actually be a bad idea. Django will choose the
> first static file it finds whose name matches, and if you had a static file
> with the same name in a *different* application, Django would be unable to
> distinguish between them. We need to be able to point Django at the right
> one, and the best way to ensure this is by *namespacing* them. That is, by
> putting those static files inside *another* directory named for the
> application itself.

Τοποθετήστε τον ακόλουθο κώδικα στο αρχείο CSS (`polls/static/polls/style.css`):

*`polls/static/polls/style.css`*

```css
li a {
    color: green;
}
```

Μετά, προσθέστε τα ακόλουθα στην αρχή του αρχείου `polls/templates/polls/index.html`:

*`polls/templates/polls/index.html`*

```html+django
{% load static %}

<link rel="stylesheet" href="{% static 'polls/style.css' %}">
```

Το template tag `{% static %}` παράγει το absolute URL των static files.

That’s all you need to do for development.

Start the server (or restart it if it’s already running):

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

*Windows*

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

Reload `http://localhost:8000/polls/` and you should see that the question
links are green (Django style!) which means that your stylesheet was properly
loaded.

## Προσθέτοντας μια background-image

Next, we’ll create a subdirectory for images. Create an `images` subdirectory
in the `polls/static/polls/` directory. Inside this directory, add any image
file that you’d like to use as a background. For the purposes of this tutorial,
we’re using a file named `background.png`, which will have the full path
`polls/static/polls/images/background.png`.

Then, add a reference to your image in your stylesheet
(`polls/static/polls/style.css`):

*`polls/static/polls/style.css`*

```css
body {
    background: white url("images/background.png") no-repeat;
}
```

Reload `http://localhost:8000/polls/` and you should see the background
loaded in the top left of the screen.

> **Warning**
>
> The `{% static %}` template tag is not available for use in static files
> which aren’t generated by Django, like your stylesheet. You should always
> use **relative paths** to link your static files between each other,
> because then you can change [`STATIC_URL`](/el/5.0/ref/settings/#std-setting-STATIC_URL) (used by the
> [`static`](/el/5.0/ref/templates/builtins/#std-templatetag-static) template tag to generate its URLs) without having to modify
> a bunch of paths in your static files as well.

Αυτά είναι τα **βασικά**. Για περισσότερες πληροφορίες σχετικά με τις ρυθμίσεις και άλλα εργαλεία τα οποία συμπεριλαμβάνονται στο Django δείτε στο άρθρο [διαχείριση των static files](/el/5.0/howto/static-files/) και στο [η εφαρμογή staticfiles](/el/5.0/ref/contrib/staticfiles/). Το άρθρο [production server και static files](/el/5.0/howto/static-files/deployment/) συζητά πως να χρησιμοποιήσετε τα static files σε ένα πραγματικό server.

Όταν είστε εξοικειωμένοι με τα static files, διαβάστε το [έβδομο μέρος αυτού του οδηγού](/el/5.0/intro/tutorial07/) για να μάθετε περισσότερα με την παραμετροποίηση του διαχειριστικού site του Django (admin site) το οποίο δημιουργείται αυτόματα.
