Почему у меня нет редиректа в Django?
Я не могу сделать редирект в Django.
Мой views.py
def blogpost(request, slug):
blog_post = Post.objects.filter(slug=slug).first()
comments = PostComment.objects.filter(post=blog_post)
context = {'blog_post':blog_post, 'comments':comments, 'user': request.user}
return render(request, 'blog/blogpost.html', context)
def post_comment(request):
if request.method == 'POST':
comment = request.POST.get('comment')
user = request.user
post_Id = request.POST.get('post_Id')
post = Post.objects.get(post_id=post_Id)
comment = BlogComment(comment=comment, user=user, post=post)
comment.save()
messages.success(request, "Your comment has been posted successfully")
return redirect(f'/blog/{post.slug}')
Я хочу перенаправить (f'/blog/{post.slug}')
Мой urls.py
urlpatterns = [
path('', views.index, name='Blog_home'),
path('<str:slug>', views.blogpost, name='blogpost'),
path('postcomment', views.post_comment, name='post_comment'),
]
Но я перенаправляю на /blog/postcomment.
HTML
<form action="/blog/postcomment" method="post">{% csrf_token %}
<input type="text" name="comment" placeholder="Enter Comment here">
<input type="hidden" name="post_id" value="{{post.post_id}}">
<input type="submit" name="submit">
</form>
Прошу любого разработчика помочь мне решить этот вопрос.