meong_j
기록하는 습관.
meong_j
전체 방문자
오늘
어제
  • 분류 전체보기 (175)
    • 개인 공부 정리 (0)
    • 서버 운영 (37)
      • Linux (36)
    • Frontend (11)
      • Vue.js (10)
    • Backend (70)
      • Java (4)
      • Python (22)
      • Django (38)
      • Spring (6)
    • Database (5)
      • Oracle (4)
      • MySQL (1)
      • MariaDB (0)
    • Android (14)
      • Kotlin (6)
    • 배포 (9)
      • Docker (8)
      • AWS (1)
    • IT_study (0)
      • Coding test (17)
      • 알고리즘 (5)
      • 스터디 (6)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • github

인기 글

반응형

태그

  • 개발자도서
  • django
  • cpu사용률
  • dp #알고리즘
  • 중첩라우트
  • 테크커리어
  • docker
  • Kotlin
  • dockersecret
  • router-link
  • 배포인프라
  • gabagecollecter
  • 안드로이드adaptor
  • SASS Variables
  • DHCP
  • 코틀린자료형
  • Proxy
  • 리눅스인증
  • 이차원배열정렬
  • 리눅스방화벽

최근 댓글

최근 글

250x250
hELLO · Designed By 정상우.
meong_j

기록하는 습관.

Backend/Django

django 03. 장고 template의 extends, include 구문과 render 함수

2021. 10. 5. 18:33
728x90
반응형

1. 장고에서 extends와 include 차이

- extends : 미리 만들어 놓은 html파일을 가져와서 이것을 바탕으로 template 채워나는 구조

- include : 조그만 조각같은 것을 가져와 붙이는 개념

 

 

2. templates 폴더 만들고 html 파일 안에 생성

{% extends 'base.html' %}
<!-- base.html 템플릿를 기반으로 안에 내용만 바꿔줌-->
{% block content %}

    <div style="border-radius: 1rem; margin: 2rem; text-align: center">
        <form action="/account/hello_world/" method="post">
            {% csrf_token %}
            <div>
             <input type="submit" class="btn btn-primary" value="POST">
            </div>
        </form>

{% endblock %}
  • hello_world.html 파일 생성
  • main App에서 작성한 base.html 로 뼈대 구성 후 extends로 안에 내용만 수정
  • account > views.py 에 html 등록

 

3. settings.py 에 TEMPLATES안에 생성한 template 등록

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

4. 소스 추가 한 것  git commit

반응형

'Backend > Django' 카테고리의 다른 글

django 05. style, 구글 폰트, 네이버 글꼴을 통해 Header, Footer 꾸미기  (0) 2021.10.05
django 04. include/ extends / block 구문을 이용한 뼈대 html 만들기  (0) 2021.10.05
django 02. Git 활성화, 환경변수 분리, commit  (0) 2021.10.05
django 01. 첫 앱 시작, 그리고 기본적인 view 만들기  (0) 2021.10.05
[Django] Settings.py 파일 공통, 개발, 운영 파일로 나누어 환경 설정 분리하기  (0) 2021.10.04
    'Backend/Django' 카테고리의 다른 글
    • django 05. style, 구글 폰트, 네이버 글꼴을 통해 Header, Footer 꾸미기
    • django 04. include/ extends / block 구문을 이용한 뼈대 html 만들기
    • django 02. Git 활성화, 환경변수 분리, commit
    • django 01. 첫 앱 시작, 그리고 기본적인 view 만들기
    meong_j
    meong_j
    #it #개발일기 #개발공부 #개발자 #백앤드 #생각정리 #시간은 실력에 비례한다 #뭐든지 꾸준히 열심히 #오늘의 내가 내일의 나를 만든다

    티스토리툴바