---
title: "첫 번째 장고 앱 작성하기, part 6"
version: 3.0
locale: ko
source: https://docs.djangoproject.com/ko/3.0/intro/tutorial06/
canonical: https://djangodocs.dev/ko/3.0/intro/tutorial06/
---
# 첫 번째 장고 앱 작성하기, part 6

이 튜토리얼은 [튜토리얼 5장](/ko/3.0/intro/tutorial05/)에 이어서 시작합니다. 우리는 테스트 된 웹 설문조사 애플리케이션을 구축했으며, 이제 스타일 시트와 이미지를 추가 할 것입니다.

서버에서 생성 된 HTML을 제외하고,  웹 어플리케이션은 일반적으로 전체 웹 페이지를 렌더링하는 데 필요한 추가 파일 — 예:이미지, JavaScript 또는 CSS — 을 제공해야합니다. Django에서는 이러한 파일을 “정적 파일” 이라고 부릅니다.

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`의 목적입니다: 이것은 각 응용 프로그램(및 여러분이 지정한 다른 위치)의 정적 파일들을 프로덕션 환경에서 쉽게 제공 할 수있는 단일 위치로 수집합니다.

> **도움을 받을 수 있는 방법**
>
> If you’re having trouble going through this tutorial, please head over to
> the [Getting Help](/ko/3.0/faq/help/) section of the FAQ.

## *앱*의 모양과 느낌을 원하는 대로 바꿔보세요.

먼저, `polls` 디렉토리에 `static` 디렉토리를 만듭니다.  `polls/templates/` 안의 템플릿을 찾는 것과 비슷하게 정적 파일을 찾습니다.

Django의 [`STATICFILES_FINDERS`](/ko/3.0/ref/settings/#std-setting-STATICFILES_FINDERS)  설정은 다양한 소스에서 정적 파일을 찾는 방법을 알고 있는 파인더 목록을 가지고 있습니다. 기본값 중 하나는 `AppDirectoriesFinder` 인데,  [`INSTALLED_APPS`](/ko/3.0/ref/settings/#std-setting-INSTALLED_APPS) 에서 “정적” 하위 디렉토리를 찾습니다, 방금 생성 한 `polls` 의 경우입니다. 관리 사이트는 정적 파일에 대해 동일한 디렉토리 구조를 사용합니다.

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.

> **정적 파일 네임스페이싱**
>
> 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.

그 스타일 시트(`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" type="text/css" href="{% static 'polls/style.css' %}">
```

`{% static %}` 템플릿 태그는 정적 파일의 절대 URL을 생성합니다.

개발에 필요한 것은 이것이 전부입니다.

서버를 시작합니다(이미 실행 중이라면 재시작합니다).

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

*Windows*

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

`http://localhost:8000/polls/`를 새로고침하면 질문의 링크가 녹색(Django 스타일!)로 표시되는 것을 볼 수 있으며, 이는 스타일시트가 올바로 적재된 것을 의미합니다.

## 배경 이미지 추가하기

다음으로, 이미지 용 하위 디렉토리를 만듭니다. `polls/static/polls/` 디렉토리에 `images` 서브 디렉토리를 만듭니다. 이 디렉토리 안에 `background.gif`라는 이미지를 넣으십시오. 즉, 이미지를 `polls/static/polls/images/background.gif`에 넣으십시오.

그런 다음, 스타일 시트(`polls/static/polls/style.css`)에 다음을 추가하세요.

*polls/static/polls/style.css*

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

`http://localhost:8000/polls/`을 새로고침하면 화면의 왼쪽 상단에 배경이 나타날 것입니다.

> **Warning**
>
> 물론 장고가 생성하지 않은 스타일 시트 같은 정적 파일에는 `{% static %}` 템플릿 태그는 사용할 수 없습니다. 정적 파일 사이에서 링크는 **상대 경로**를 사용해야합니다. [`STATIC_URL`](/ko/3.0/ref/settings/#std-setting-STATIC_URL)  ([`static`](/ko/3.0/ref/templates/builtins/#std-templatetag-static) 템플릿 태그가 URL을 생성하기 위해 사용)을 변경할 수 있기 때문에 정적 파일에서 여러 경로를 수정할 필요가 없습니다.

지금까지의 내용은 **기본**입니다. 프레임워크에 포함된 설정 및 다른 것들에 대한 자세한 내용은 [정적 파일 howto](/ko/3.0/howto/static-files/)와 [정적 파일 레퍼런스](/ko/3.0/ref/contrib/staticfiles/)를 참조하십시오. [정적 파일 배포](/ko/3.0/howto/static-files/deployment/)는 실제 서버에서 정적 파일을 사용하는 방법을 설명합니다.

정적 파일에 익숙해졌으면, Django의 자동 생성되는 관리자 사이트를 커스터마이징하는 법에 대해 배울 수 있는 [이 튜토리얼의 7장](/ko/3.0/intro/tutorial07/)을 보세요.
