반복된 내용을 작성하기가 매우 힘이드니 약식으로 설명한다.
#views.py
class PostDeleteView(DeleteView):
model = Post
template_name = "posts/post_confirm_delete.html"
pk_url_kwarg = "post_id"
context_object_name = "post"
def get_success_url(self):
return reverse("post-list")
삭제 확인 페이지
로 이동하기 위해post_confirm_delete.html
템플릿
을 렌더한다.
삭제 후
포스트 목록 페이지
로 이동한다.
#urls.py
urlpatterns = [
# path('', views.index),
path('', views.PostListView.as_view(), name="post-list"),
path('posts/new/', views.PostCreateView.as_view(), name="post-create"),
path('posts/<int:post_id>/', views.PostDetailView.as_view(), name="post-detail"),
path('posts/<int:post_id>/edit/', views.PostUpdateView.as_view(), name="post-update"),
path('posts/<int:post_id>/delete/', views.PostDeleteView.as_view(), name="post-delete"),
]