Skip to content

Commit a498191

Browse files
authored
Merge pull request #14 from zablon-oigo/detail-post
Detail post
2 parents 5fd1cef + 44af47f commit a498191

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

β€Žblog/templates/blog/home.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<a class="mr-2" href="#">{{ post.author }}</a>
1010
<small class="text-muted">{{ post.date_posted | date:"F d, Y" }}</small>
1111
</div>
12-
<h2><a class="article-title" href="#">{{ post.title }}</a></h2>
12+
<h2><a class="article-title" href="{% url 'detail' post.id %}">{{ post.title }}</a></h2>
1313
<p class="article-content">{{ post.content }}</p>
1414
</div>
1515
</article>
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends "blog/base.html" %}
2+
{% load static %}
3+
{% block content %}
4+
5+
<article class="media content-section">
6+
<div class="media-body">
7+
<div class="article-metadata">
8+
<img src="{% static post.author.image %}" alt="">
9+
<a class="mr-2" href="#">{{ post.author }}</a>
10+
<small class="text-muted">{{ post.date_posted | date:"F d, Y" }}</small>
11+
</div>
12+
<h2><a class="article-title" href="">{{ post.title }}</a></h2>
13+
<p class="article-content">{{ post.content }}</p>
14+
</div>
15+
</article>
16+
{% endblock %}

β€Žblog/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
path("", views.home, name="blog-home"),
77
path("about/", views.about, name="blog-about"),
88
path("create-post/", views.create_post, name="create_post"),
9+
path("detail/<int:pk>/", views.post_detail, name="detail"),
910
]

β€Žblog/views.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.contrib import messages
22
from django.contrib.auth.decorators import login_required
3-
from django.shortcuts import redirect, render
3+
from django.shortcuts import get_object_or_404, redirect, render
44

55
from .forms import PostForm
66
from .models import Post
@@ -15,6 +15,12 @@ def about(request):
1515
return render(request, "blog/about.html", {"title": "About"})
1616

1717

18+
def post_detail(request, pk):
19+
post = get_object_or_404(Post, pk=pk)
20+
context = {"post": post}
21+
return render(request, "blog/post_detail.html", context)
22+
23+
1824
@login_required
1925
def create_post(request):
2026
if request.method == "POST":

0 commit comments

Comments
Β (0)