creatd_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
: 객체가 최초로 생성될 때의 날짜와 시간을 기록
: 이후 객체가 수정되어도 값이 변경되지 않음
: 일반적으로 생성일에 사용
: 한 번만 저장되고 수정되지 않아서 생성일 전용으로 적합
: 객체가 저장될 때마다 현재 날짜와 시간으로 자동 갱신
: 수정일에 주로 사용
: 매번 저장할 때마다 갱신되므로 업데이트 전용으로 적합
: 상속 개념으로 기본 구조를 정의한 부모 템플릿을 확장할 때 사용
: 템플릿 상속을 통해 기본 레이아웃을 만들고 각 페이지별 공통 부분을 유지하면서 일부만 바꾸기 좋음
: 코드 조각을 다른 템플릿에 삽입할 때 사용
: 재사용할 수 있는 작은 부분을 여러 템플릿에서 불러올 때 유용
: 독립적인 HTML 컴포넌트를 나눠서 관리할 때 사용
{% extends "layout/base.html" %}
{% load humanize %}
{% block head %}
{% include "layout/head.html" %}
{% endblock head %}
{% block navi %}
{% include "layout/navbar.html" %}
{% endblock navi %}
{% block header %}
{% include "layout/header.html" %}
{% endblock header %}
{% block content %}
<!-- Section-->
<section class="py-5">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
<!-- dev_5 상품 카드 -->
{% for product in products %}
<div class="col mb-5">
<div class="card h-100">
<!-- dev_6 세일 뱃지 처리 -->
{% if product.is_sale %}
<!-- Sale badge-->
<div class="badge bg-dark text-white position-absolute" style="top: 0.5rem; right: 0.5rem">Sale</div>
{% endif %}
<!-- Product image-->
<img class="card-img-top" src="{{ product.image.url }}" alt="..." style="height:15rem; object-fit:cover;" />
<!-- Product details-->
<div class="card-body p-4">
<div class="text-center">
<!-- Product name-->
<h5 class="fw-bolder">{{ product.name }}</h5>
<!-- Product reviews-->
<div class="d-flex justify-content-center small text-warning mb-2">
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
</div>
<!-- Product price-->
<!-- dev_6 세일 가격 처리 -->
{% if product.is_sale %}
<span class="text-muted text-decoration-line-through">{{ product.price|floatformat:0|intcomma }}원</span>
{{ product.sale_price|floatformat:0|intcomma }}원
{% else %}
{{ product.price|floatformat:0|intcomma }}원
{% endif %}
</div>
</div>
<!-- Product actions-->
<div class="card-footer p-4 pt-0 border-top-0 bg-transparent">
<div class="text-center">
<a class="btn btn-outline-dark mt-auto" href="#">Add to cart</a>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</section>
{% endblock content %}
{% block footer %}
{% include "layout/footer.html" %}
{% endblock footer %}
이런 식으로 가운데 content만 바꾸고 나머지는 extends나 include를 사용하면 코드를 재사용할 수 있다.