Hello! I have a problem. When deleting a comment, the error Post matching query does not exist appears

I have a problem. When deleting a comment, the error Post matching query does not exist appears. And I do not know what to do with it. Thank you in advance! Error: Does Not Exist at /news/post/6
Post matching query does not exist.

Note! I use the django framework

Here is the code:
views.py:

from django.shortcuts import render
from django.urls import reverse_lazy
from .forms import PostForm, CommentForm
from .models import Post, Comment
from django.views import View
from django.views.generic.edit import UpdateView, DeleteView


class PostListView(View):
    def get(self, request, *args, **kwargs):
        posts = Post.objects.all().order_by('-created_on')
        form = PostForm()

        context = {
            'post_list': posts,
            'form': form,
        }
        return render(request, 'news/post_list.html', context)

    def post(self, request, *args, **kwargs):
        posts = Post.objects.all().order_by('-created_on')
        form = PostForm(request.POST)

        if form.is_valid():
            new_post = form.save(commit=False)
            new_post.author = request.user
            new_post.save()

        context = {
            'post_list': posts,
            'form': form,
        }
        return render(request, 'news/post_list.html', context)


class PostDetailView(View):
    def get(self, request, pk, *args, **kwargs):
        post = Post.objects.get(pk=pk)
        form = CommentForm()

        comments = Comment.objects.filter(post=post).order_by('-created_on')

        context = {
            'post': post,
            'form': form,
            'comments': comments,
        }
        return render(request, 'news/details_view.html', context)

    def post(self, request, pk, *args, **kwargs):
        post = Post.objects.get(pk=pk)
        form = CommentForm(request.POST)

        if form.is_valid():
            new_comment = form.save(commit=False)
            new_comment.author = request.user
            new_comment.post = post
            new_comment.save()

        comments = Comment.objects.filter(post=post).order_by('-created_on')

        context = {
            'post': post,
            'form': form,
            'comments': comments,
        }
        return render(request, 'news/details_view.html', context)


class PostEditView(UpdateView):
    model = Post
    fields = ['body']
    template_name = 'news/post_edit.html'

    def get_success_url(self):
        pk = self.kwargs['pk']
        return reverse_lazy('post-detail', kwargs={'pk': pk})


class PostDeleteView(DeleteView):
    model = Post
    template_name = 'news/post_delete.html'
    success_url = reverse_lazy('post-list')


class CommentDeleteView(DeleteView):
    model = Comment
    template_name = 'news/comment_delete.html'

    def get_success_url(self):
        pk = self.kwargs['pk']
        return reverse_lazy('post-detail', kwargs={'pk': pk})

comment_delete.html:

{% extends 'main/layout.html' %}
{% load crispy_forms_tags %}
{% load static %}

{% block content%}
<link rel="stylesheet" href="{% static 'news/css/post_list.css'%}">
<div class="container">
    <div class="row mt-5">
        <div class="col-md-5 col-sm-6">
            <a href="{% url 'post-detail' object.pk %}" class="btn btn-light">Вернуться обратно</a>
        </div>
    </div>

    <div class="row justify-content-center mt-3 mb-5">
        <div class="col-md-5 col-sm-12 border-bottom">
            <form method="POST" class="form">
                {% csrf_token %}
                <h5>Вы уверены?</h5>
                <p>Вы уверены, что хотите удалить комментарий это невозможно отменить</p>
                <div class="d-grid gap-2">
                    <button class="btn btn-danger mt-3">Удалить</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock content %}

details_view.html:

{% extends 'main/layout.html' %}
{% load crispy_forms_tags %}
{% load static %}

{% block title%}Post{% endblock %}

{% block content%}
<link rel="stylesheet" href="{% static 'news/css/post_list.css'%}">
<div class="container">
    <div class="row mt-5">
        <div class="col-md-5 col-sm-6">
            <a href="{% url 'post-list' %}" class="btn btn-light">Вернуться обратно</a>
        </div>
    </div>

    <div class="row justify-content-center mt-3">
        <div class="col-md-5 col-sm-12 border-bottom">
            <p>
                <strong>{{ post.author }}</strong> {{ post.created_on }}
                {% if request.user == post.author %}
                    <a href="{% url 'post-edit' post.pk %}" style="color: #333;"><i class="far fa-edit"></i></a>
                    <a href="{% url 'post-delete' post.pk %}" style="color: #333;"><i class="far fa-trash"></i></a>
                {% endif %}
            </p>
            <p>{{ post.body }}</p>
        </div>
    </div>

    <div class="row justify-content-center mt-3 mb-5">
        <div class="col-md-5 col-sm-12">
            <form method="POST" class="form">
                {% csrf_token %}
                {{ form | crispy }}
                <div class="d-grid gap-2">
                    <button class="btn btn-success mt-3">Написать</button>
                </div>
            </form>
        </div>
    </div>
    {% for comment in comments %}
    <div class="row justify-content-center mt-3 mb-5 border-bottom">
        <div class="col-md-5 col-sm-12">
            <p>
                <strong>{{ comment.author }}</strong> {{ comment.created_on }}
                {% if request.user == post.author %}
                    <a href="{% url 'comment-delete' post.pk comment.pk %}" style="color: #333;"><i class="far fa-trash"></i></a>
                {% endif %}
            </p>
            <p>{{ comment.comment }}</p>
        </div>
    </div>
    {% endfor %}
</div>
{% endblock content %}

news/urls.py:

from django.urls import path
from . import views
from .views import PostListView, PostDetailView, PostEditView, PostDeleteView, CommentDeleteView

urlpatterns = [
    path('', PostListView.as_view(), name='post-list'),
    path('post/<int:pk>', PostDetailView.as_view(), name='post-detail'),
    path('post/edit/<int:pk>', PostEditView.as_view(), name='post-edit'),
    path('post/delete/<int:pk>', PostDeleteView.as_view(), name='post-delete'),
    path('post/<int:post_pk>/comment/delete/<int:pk>', CommentDeleteView.as_view(), name='comment-delete'),
]

I’ve tried articles and videos from YouTube

New contributor

Lemon Studios is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật