코딩(개발)/Django

홈페이지 제작 실습 STEP 3 (공통layout)

플랜데버 2021. 1. 16. 11:48

전체 같이 쓰는 베이스 페이지 제작

- miiusoft\templates\layout.html

- header.html

- sidebar.html

- footer.html

{% load static %}
<!doctype html>
<html lang="ko">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.min.css' %}">
    <!-- pybo CSS -->
    <link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
    <title>welcome to myshop</title>
</head>
<body>

{% include "header.html" %}

<div class="container my-3">
    <div class="row justify-content-between my-3">
        <div class="col-8">
            <!-- 기본 템플릿 안에 삽입될 내용 Start -->
            {% block content %}
            {% endblock %}
            <!-- 기본 템플릿 안에 삽입될 내용 End -->
        </div>
        <div class="col-2">
            {% include "sidebar.html" %}
        </div>
    </div>
</div>

<!-- jQuery JS -->
<script src="{% static 'js/jquery-3.4.1.min.js' %}"></script>
<!-- Bootstrap JS -->
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<!-- 자바스크립트 Start -->
{% block script %}
{% endblock %}
<!-- 자바스크립트 End -->
</body>
</html>

* 원하는 레이아웃으로 수정

 

2. 적용방법

{% extends "layout.html" %}
{% block content %}
{% load static %}

welcome to miiusoft 

{% endblock %}   

* template 폴더에 들어있는 다른 앱의 베이스페이지들도 별다른 연결없이 모두 상속 받아 사용 가능.