django

include와 extends 이용 (pinterest clone 9강)

개복신 개발자 2021. 7. 14. 13:01
반응형

-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을 실행시킴

반응형