views.py
from .models import Post
from django.views.generic import DetailView
class postview(DetailView):
model = Post (Import your post models)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('post/<int:pk>',views.postview.as_view(),name='post-view'),
]
post_detail.html
{% block content %}
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}">
<div class="media-body">
<div class="article-metadata">
<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="{% url 'post-view' post.id %}">{{ post.title }}</a></h2>
<p class="article-content">{{ post.body }}</p>
</div>
</article>
{% endblock content %}
Top comments (0)