저번 글에서 만든 페이지 상단에 Bookmark, Blog를 클릭했을 때 화면이 표기되고
해당 사이트의 모든 페이지를 첫 페이지의 룩앤필에 맞추기 위해
base.html 템플릿을 상속받아 각 페이지들을 개선한다.
템플릿 코드만 base.html의 상속을 받아 고쳐주면 되므로 템플릿 파일만 수정해준다.
수정되어야 하는 코드는 다음과 같다.
# bookmark_list.html
{% extends "base.html" %}
{% block title %}bookmark_list.html{% endblock %}
{% block content %}
<h1>Bookmark List</h1>
<br>
<ul>
{% for bookmark in object_list %}
<li><a href="{% url 'bookmark:detail' bookmark.id %}">{{ bookmark }}</a></li>
{% endfor %}
</ul>
{% endblock %}
# bookmark_detail.html
{% extends "base.html" %}
{% block title %}bookmark_detail.html{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<ul>
<li>URL: <a href="{{ object.url }}">{{ object.url }}</a></li>
</ul>
{% endblock %}
# post_all.html
{% extends "base.html" %}
{% block title %}post_all.html{% endblock %}
{% block content %}
<h1>Blog List</h1>
<br>
{% for post in posts %}
<h3><a href='{{ post.get_absolute_url }}'>{{ post.title }}</a></h3>
{{ post.modify_date|date:"N d, Y" }}
<p>{{ post.description }}</p>
{% endfor %}
<br>
<div>
<span>
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}">PreviousPage</a>
{% endif %}
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">NextPage</a>
{% endif %}
</span>
</div>
{% endblock %}
# post_archive_day.html
{% extends "base.html" %}
{% block title %}post_archive_day.html{% endblock %}
{% block content %}
<h1>Post Archives for {{ day|date:"N d, Y" }}</h1>
<br><br>
<div>
<ul>
{% for post in object_list %}
<li class="h5">
{{ post.modify_dt|date:"Y-m-d" }} 
<a href="{{ post.get_absolute_url }}"><strong>{{ post.title }}</strong></a>
</li>
{% endfor %}
</ul>
</div>
{% endblock %}
# post_acrchive_month.html
{% extends "base.html" %}
{% block title %}post_archive_month.html{% endblock %}
{% block content %}
<h1>Post Archives for {{ month|date:"N, Y" }}</h1>
<br><br>
<div>
<ul>
{% for post in object_list %}
<li class="h5">
{{ post.modify_dt|date:"Y-m-d" }} 
<a href="{{ post.get_absolute_url }}"><strong>{{ post.title }}</strong></a>
</li>
{% endfor %}
</ul>
</div>
{% endblock %}
# post_archive_year.html
{% extends "base.html" %}
{% block title %}post_archive_year.html{% endblock %}
{% block content %}
<h1>Post Archives for {{ year|date:"Y" }}</h1>
{% for date in date_list %}
<a href="{% url 'blog:post_month_archive' date|date:'Y' date|date:'b' %}"
class="btn btn-outline-primary btn-sm mx-1">
{{ date|date:"F" }}</a>
{% endfor %}
<br><br>
<div>
<ul>
{% for post in object_list %}
<li class="h5">
{{ post.modify_dt|date:"Y-m-d" }} 
<a href="{{ post.get_absolute_url }}"><strong>{{ post.title }}</strong></a>
</li>
{% endfor %}
</ul>
</div>
{% endblock %}
# post_archive.html
{% extends "base.html" %}
{% block title %}post_archive.html{% endblock %}
{% block content %}
<h1>Post Archives until {% now "N d, Y" %}</h1>
{% for date in date_list %}
<a href="{% url 'blog:post_year_archive' date|date:'Y' %}"
class="btn btn-outline-primary btn-sm mx-1">
Year-{{ date|date:"Y" }}</a>
{% endfor %}
<br><br>
<div>
<ul>
{% for post in object_list %}
<li class="h5">
{{ post.modify_dt|date:"Y-m-d" }} 
<a href="{{ post.get_absolute_url }}"><strong>{{ post.title }}</strong></a>
</li>
{% endfor %}
</ul>
</div>
{% endblock %}
# post_detail.html
{% extends "base.html" %}
{% block title %}post_detail.html{% endblock %}
{% block content %}
<h2>{{ object.title }}</h2>
<p>
{% if object.get_next %}
<a href="{{ object.get_next.get_absolute_url }}" title="View previous post">
<i class="fas fa-arrow-circle-left"></i> {{ object.get_next }}
</a>
{% endif %}
{% if object.get_previous %}
| <a href="{{ object.get_previous.get_absolute_url }}" title="View next post">
{{ object.get_previous }} <i class="fas fa-arrow-circle-right"></i>
</a>
{% endif %}
</p>
<div>{{ object.modify_dt|date:"j F Y" }}</div>
<br>
<div>
{{ object.content|linebreaks }}
</div>
{% endblock %}
'Django' 카테고리의 다른 글
[Django] Blog 앱 확장 - 댓글 달기 (0) | 2022.07.30 |
---|---|
[Django] Blog 앱 확장 - Tag 달기 (0) | 2022.07.30 |
[Django] 첫 페이지 만들기 (0) | 2022.07.22 |
[Django] Blog 앱 개발 (0) | 2022.07.22 |
[Django] 가상환경 설정, Bookmark 앱 개발 (0) | 2022.07.20 |