I am creating my first blog with django and I am experiencing a problem when posting comments and that is that the same comments are added to all the posts I make. Please, I would love a solution since I have tried EVERYTHING.
Here I leave you my template, views and models:
def blog_created(request, post_id):
post = get_object_or_404(Post, id=post_id)
comments = Comments.objects.filter(post=post)
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.author = request.user
comment.post = post
comment.save()
comments = Comments.objects.filter(post=post)
else:
form = CommentForm()
return render(request, "blog_created.html", {"post": post, "comments": comments, "form": form})