在Django中刷新页面后,表单继续提交吗?

时间:2020-08-15 10:05:26

标签: django django-models django-forms django-views django-templates

我对自己的帖子有一个评论部分,当我提交评论时,在不断向帖子中添加相同评论后刷新页面。我想我有点知道应该重定向页面,但是我对应该重定向的地方感到困惑。这是我的。代码:

def post_detail(request, year, month, day, post):
  #some code
  if request.method == 'POST':
     new_comment.save()
     return HttpResponseRedirect(reverse("blog:post_detail"))
   else:
     comment_form = CommentForm()
   return render(request,
             'blog/post/detail.html',
             {'post': post,
              'comments': comments,
              'new_comment': new_comment,
              'comment_form': comment_form,
              'similar_posts': similar_posts, 'tags': tags })

我想问题出在这里– blog:post_detail--我在提交评论表单时http://127.0.0.1:8000/2020/8/13/post1/

应该重定向到哪里?
urlpatterns = [
                # post views
                path('', views.post_list, name='post_list'),
                path('<int:year>/<int:month>/<int:day>/<slug:post>/',views.post_detail,name='post_detail'),
                path('<int:post_id>/share/',views.post_share, name='post_share'),
                path('tag/<slug:tag_slug>/',views.post_list, name='post_list_by_tag'),
                path('feed/', LatestPostsFeed(), name='post_feed'),
                path('search/', views.post_search, name='post_search'),
                path('about/', views.about, name='about_page'),
                path('contact/', views.contact, name='contact_page'),
]

我的帖子是detail.html模板

任何帮助将不胜感激。谢谢

0 个答案:

没有答案