Skip to content

Commit 4dd5d79

Browse files
committed
3d. Blog App: Templates
1 parent 8ae8693 commit 4dd5d79

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% extends "base.html" %}
2+
{% block page_content %}
3+
<div class="col-md-8 offset-md-2">
4+
<h1>{{ category | title }}</h1>
5+
<hr>
6+
{% for post in posts %}
7+
<h2><a href="{% url 'blog_detail' post.pk%}">{{ post.title }}</a></h2>
8+
<small>
9+
{{ post.created_on.date }} |&nbsp;
10+
Categories:&nbsp;
11+
{% for category in post.categories.all %}
12+
<a href="{% url 'blog_category' category.name %}">
13+
{{ category.name }}
14+
</a>&nbsp;
15+
{% endfor %}
16+
</small>
17+
<p>{{ post.body | slice:":400" }}...</p>
18+
{% endfor %}
19+
</div>
20+
{% endblock %}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{% extends "base.html" %}
2+
{% block page_content %}
3+
<div class="col-md-8 offset-md-2">
4+
<h1>{{ post.title }}</h1>
5+
<small>
6+
{{ post.created_on.date }} |&nbsp;
7+
Categories:&nbsp;
8+
{% for category in post.categories.all %}
9+
<a href="{% url 'blog_category' category.name %}">
10+
{{ category.name }}
11+
</a>&nbsp;
12+
{% endfor %}
13+
</small>
14+
<p>{{ post.body | linebreaks }}</p>
15+
<h3>Leave a comment:</h3>
16+
<form action="/blog/{{ post.pk }}/" method="post">
17+
{% csrf_token %}
18+
<div class="form-group">
19+
{{ form.author }}
20+
</div>
21+
<div class="form-group">
22+
{{ form.body }}
23+
</div>
24+
<button type="submit" class="btn btn-primary">Submit</button>
25+
</form>
26+
<h3>Comments:</h3>
27+
{% for comment in comments %}
28+
<p>
29+
On {{comment.created_on.date }}&nbsp;
30+
<b>{{ comment.author }}</b> wrote:
31+
</p>
32+
<p>{{ comment.body }}</p>
33+
<hr>
34+
{% endfor %}
35+
</div>
36+
{% endblock %}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% extends "base.html" %}
2+
3+
{% block page_content %}
4+
<div class="col-md-8 offset-md-2">
5+
<h1>Blog Index</h1>
6+
<hr>
7+
{% for post in posts %}
8+
<h2><a href="{% url 'blog_detail' post.pk%}">{{ post.title }}</a></h2>
9+
<small>
10+
{{ post.created_on.date }} |&nbsp;
11+
Categories:&nbsp;
12+
{% for category in post.categories.all %}
13+
<a href="{% url 'blog_category' category.name %}">
14+
{{ category.name }}
15+
</a>&nbsp;
16+
{% endfor %}
17+
</small>
18+
<p>{{ post.body | slice:":400" }}...</p>
19+
{% endfor %}
20+
</div>
21+
{% endblock %}

rp-portfolio/personal_portfolio/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<a class="nav-link" href="{% url 'project_index' %}">Home</a>
1414
</li>
1515
<li class="nav-item">
16-
<a class="nav-link" href="#">Blog</a>
16+
<a class="nav-link" href="{% url 'blog_index' %}">Blog</a>
1717
</li>
1818
</ul>
1919
</div>

0 commit comments

Comments
 (0)