[django] 점프 투 장고 - 장고 기초 7

Joy·2020년 6월 17일
0

Django | 점프투장고

목록 보기
9/22

스태틱

페이지에 디자인 적용하기 - 스타일 시트 파일 이용.


Static dir

스타일시트 파일은 장고의 스태틱 디렉터리에 저장

  • config/settings.py 파일에 등록
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
  • 'static' dir 생성



스타일 시트

  • 파일 생성

경로: C:\projects\mysite\static

  • style.css 작성
textarea {
    width:100%;
}

input[type=submit] {
    margin-top:10px;
}



탬플릿에 스타일 적용

  • 탬플릿 파일 수정

스타일시트 적용해주는 코드 추가

{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">

스태틱파일을 사용하기 위해서는 템플릿 가장 상단에 {% load static %} 태그를 삽입해야 함



결과

profile
roundy

0개의 댓글