Dangango詳細ビュー(ポスト詳細)
3488 ワード
ビューパイ
from .models import Post
from django.views.generic import DetailView
class postview(DetailView):
model = Post (Import your post models)
URL.パイfrom django.urls import path
from . import views
urlpatterns = [
path('post/<int:pk>',views.postview.as_view(),name='post-view'),
]
後の詳細.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 %}
Reference
この問題について(Dangango詳細ビュー(ポスト詳細)), 我々は、より多くの情報をここで見つけました https://dev.to/phansivang/django-detail-view-post-detail-2k2cテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol