Когда я нажимаю кнопку "PUBLISH COMMENT BUTTON", комментарии не публикуются в моем фронтенде в django

Я делаю раздел комментариев в django, но когда я нажимаю на раздел комментариев, комментарий публикуется в разделе комментариев моего сайта, он просто обновляет страницу и ничего не делает, но когда я добавляю комментарий из моего бэкэнда, который является разделом администратора, он работает совершенно нормально и обновляется в моем фронтэнде, но форма комментария в деталях моих записей блога не работает, позвольте мне показать часть моего кода

views.py

# this view returns the blog details and the comment section with the form
def blog_detail(request, blog_slug):
    post = get_object_or_404(Blog, slug=blog_slug)
    # post = Blog.objects.filter(slug=blog_slug)
    categories = Category.objects.all()
    comments = post.comments.filter(active=True)
    new_comment = None
    if request.method == "POST":
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            new_comment = comment_form.save(commit=False)
            new_comment.post = post
            new_comment.name = request.user
            new_comment.save()
    else:
        comment_form = CommentForm()

    context = {
        'post': post,
        'comments': comments,
        'comment_form': comment_form,
        'new_comment': new_comment,
        'categories': categories,
    }
    return render(request, 'blog/blog-details.html', context)

forms.py

class CommentForm(forms.ModelForm):
    # tags = forms.CharField(widget=forms.TextInput(attrs={'class': 'input is-medium'}), required=True)
    
    class Meta:
        model = Comment
        fields = ['email', 'body']

admin.py

@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = ('name', 'body', 'post', 'created_on')
    list_filter = ('active', 'created_on')
    search_fields = ['approve_comment']

    def approve_comment(self, request, queryset):
        queryset.update(active=True)

models.py

class Comment(models.Model):
    post = models.ForeignKey(Blog, on_delete=models.CASCADE, related_name='comments')
    name = models.ForeignKey(User, on_delete=models.DO_NOTHING, verbose_name="Name")
    email = models.EmailField()
    body = models.TextField(verbose_name="Write Comment")
    created_on = models.DateTimeField(auto_now_add=True)
    active = models.BooleanField(default=True)

    class Meta:
        ordering = ['-created_on']

    def __str__(self):
        return 'Comment: {} by {}'.format(self.body, self.name)

blogdetail.html в этом шаблоне также отображаются формы комментариев

<div class="comment-form">
                                            <form action="#">
                                                <div class="row">
                                                    {% if new_comment %}
                                                    <div class="alert alert-success" role="alert">
                                                        Your comment is awating approval
                                                    </div>
                                                    {% else %}
                                                    <form method="POST">
                                                        {% csrf_token %}
                                                        {{comment_form|crispy}} <br>
                                                        <button type="submit">Post Comment</button>
                                                        
                                                    </form>
                                                    {% endif %}
                                                </div>
                                            </form>
                                        </div>

я пробовал много способов исправить это, но в итоге ничего не получается, и заметьте, я не получаю никакой ошибки, просто обновляется страница, а затем не появляются комментарии.

любая помощь будет очень признательна

шаблон

<div class="comment-form">
                                            
                                                <div class="row">
                                                    {% if new_comment %}
                                                    <div class="alert alert-success" role="alert">
                                                        Your comment is awating approval
                                                    </div>
                                                    {% else %}
                                                    <form action="" method="POST">
                                                        {% csrf_token %}
                                                        {{comment_form|crispy}} <br>
                                                        <button type="submit">Post Comment</button>
                                                        
                                                    </form>
                                                    {% endif %}
                                                </div>
                                           
                                        </div>

views.py

def blog_detail(request, blog_slug):
    post = get_object_or_404(Blog, slug=blog_slug)
    # post = Blog.objects.filter(slug=blog_slug)
    categories = Category.objects.all()
    comments = post.comments.filter(active=True)
    new_comment = post.comments.filter(active=False,name=request.user)
    if request.method == "POST":
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            new_comment = comment_form.save(commit=False)
            new_comment.post = post
            new_comment.name = request.user
            new_comment.active = False #this make the comment non active until it is approuved by admin
            new_comment.save()
            return redirect('the-url-of-the-blog-detail')

    else:
        comment_form = CommentForm()

    context = {
        'post': post,
        'comments': comments,
        'comment_form': comment_form,
        'new_comment': new_comment,
        'categories': categories,
    }
    return render(request, 'blog/blog-details.html', context)
Вернуться на верх