상세 컨텐츠

본문 제목

include와 extends 이용 (pinterest clone 9강)

django

by 개복신 개발자 2021. 7. 14. 13:01

본문

728x90
반응형

-Base.html 구성

<!DOCTYPE html>
<html lang="ko">

{% include 'head.html' %}
<body>
    {% include 'header.html' %}

    {% block content %}
	{% endblock %}

    {% include 'footer.html' %}
   

</body>
</html>

inclued는 다른 template를 import하는 개념으로 이해하면 됨

templates 폴더 안에 다른 파일들을 include    (import 개념)

-Header.html은 상단바에 대한 내용

-footer.html은 하단바에 대한 내용

 

accountapp 앱 내의 templates에 hello_world.html-->

{% extends 'base.html' %}

{% block content%}

    <div style="height: 20rem; background-color: azure; border-radius: 1rem; margin: 2rem;">
        <h1>testing</h1>
    </div>
{% endblock %}

-{block content} ~ {endblock} 사이에 코드 작성 -->base.html이 씌어지고 그 사이에 작성된 코드들이 적용됨

 


accountapp내 views.py-->

def hello_world(request):
    return render(request, 'accountapp/hello_world.html')

-accountapp내의 hello_world.html을 실행시킴

반응형

'django' 카테고리의 다른 글

models.py class 작성 (14강)  (0) 2021.07.15
static 설정(11강)  (0) 2021.07.15
부트스트랩 적용 (10강)  (0) 2021.07.15
templates내용 뜨게 하기(pinterest clone 8강)  (0) 2021.07.14
django project 시작(pinterest clone 5강)  (0) 2021.07.14

관련글 더보기

댓글 영역