Skip to content

Commit

Permalink
Merge pull request #14 from zablon-oigo/detail-post
Browse files Browse the repository at this point in the history
Detail post
  • Loading branch information
Akash1362000 authored Feb 25, 2024
2 parents 5fd1cef + 44af47f commit a498191
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion blog/templates/blog/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<a class="mr-2" href="#">{{ post.author }}</a>
<small class="text-muted">{{ post.date_posted | date:"F d, Y" }}</small>
</div>
<h2><a class="article-title" href="#">{{ post.title }}</a></h2>
<h2><a class="article-title" href="{% url 'detail' post.id %}">{{ post.title }}</a></h2>
<p class="article-content">{{ post.content }}</p>
</div>
</article>
Expand Down
16 changes: 16 additions & 0 deletions blog/templates/blog/post_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "blog/base.html" %}
{% load static %}
{% block content %}

<article class="media content-section">
<div class="media-body">
<div class="article-metadata">
<img src="{% static post.author.image %}" alt="">
<a class="mr-2" href="#">{{ post.author }}</a>
<small class="text-muted">{{ post.date_posted | date:"F d, Y" }}</small>
</div>
<h2><a class="article-title" href="">{{ post.title }}</a></h2>
<p class="article-content">{{ post.content }}</p>
</div>
</article>
{% endblock %}
1 change: 1 addition & 0 deletions blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
path("", views.home, name="blog-home"),
path("about/", views.about, name="blog-about"),
path("create-post/", views.create_post, name="create_post"),
path("detail/<int:pk>/", views.post_detail, name="detail"),
]
8 changes: 7 additions & 1 deletion blog/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, render
from django.shortcuts import get_object_or_404, redirect, render

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


def post_detail(request, pk):
post = get_object_or_404(Post, pk=pk)
context = {"post": post}
return render(request, "blog/post_detail.html", context)


@login_required
def create_post(request):
if request.method == "POST":
Expand Down

0 comments on commit a498191

Please sign in to comment.