장고에서는 이미지, 자바스크립트, 그리고 css 등을  정적파일(static files)이라고 하는데,  django.contrib.staticfiles 을 통해 정적파일을 관리하게 된다.
그러면 아래에서 위의 정적파일(Configuring static files)을 구성하는 방법을 알아보자.
아래와 같이 settings.py 파일 INSTALLED_APPS 항목에  'django.contrib.staticfiles', 가 포함되어 있는지 확인한다.
1 2 3 4 5 6 7 8 9  | INSTALLED_APPS = [     'suit',     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles',     'django.contrib.sites',  | cs | 
settings.py 파일 STATIC_URL 의 위치를 다음과 같이 정해준다.
아래와 같이 어플리케이션 안에 static 폴더를 만든다.
1  | STATIC_URL = '/static/'  | cs | 
/static/my_app/myexample.jpg 와 같이 하드코딩하거나  아래와 같이 정적 탬플릿 태그를 사용할 수도 있다. 
https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-STATICFILES_STORAGE
1 2  | {% load staticfiles %}     <img src="{% static "my_app/myexample.jpg" %}" alt="My image"/>  | cs | 
위에서 만든 static 폴더내의 파일 저장한다. 
예를 들면, 아래와 같이 파이어폭스 로고를 사이트 상단에 올려보자.
해당 파일을 다운로드 받아 앞에서 만든 static 폴더에 넣은 후 넣고자 하는 html 파일을 열고 6행와 같은 식으로 코드를 입력하면 된다.
1 2 3 4 5 6  | {% load static %} <!-- link rel="stylesheet" href="{% static "admin/css/base.css" %}" / --> <title>{% block title %}site:bourne{% endblock %}</title> </head> <body> <img src="{% static 'firefox-dev-ed_logo-only_1024.png' %}">  | cs | 
* Deploying static files 관련내용
https://docs.djangoproject.com/en/1.9/howto/static-files/deployment/
'Season 1 아카이브 > 프로그래밍' 카테고리의 다른 글
| 셀레늄 버전 체크 how to check the version of the Selenium API installed (0) | 2015.12.19 | 
|---|---|
| 디렉토리 구조 출력 tree 패키지 (0) | 2015.12.16 | 
| Django Suit 설치 - 장고 어드민 인터페이스 모던 테마 적용하기 (0) | 2015.12.09 | 
| 장고 마키나 설치하기 (4) - 에러 처리 DoesNotExist: Site matching query does not exist (0) | 2015.12.03 | 
| 장고 마키나 설치하기 (3) Django-machina Project configuration - Django-haystack settings/migration/URLs (1) | 2015.12.03 |