目前,如果表单上有任何错误,django.contrib.comments 会将用户发送到预览页面。
我在博客的上下文中使用评论,如果提交出现问题,我更希望用户留在他们所在的页面上。据我所知,这是在 django.contrib.comments.views.comments.post_comment 中硬编码的:
# If there are errors or if we requested a preview show the comment
if form.errors or preview:
template_list = [
"comments/%s_%s_preview.html" % tuple(str(model._meta).split(".")),
"comments/%s_preview.html" % model._meta.app_label,
"comments/preview.html",
]
return render_to_response(
template_list, {
"comment" : form.data.get("comment", ""),
"form" : form,
"next": next,
},
RequestContext(request, {})
)
有什么方法可以在不将源代码更改为 django.contrib.comments 的情况下更改此行为?
任何指针将不胜感激......
谢谢!
最佳答案
看起来你有两个真正的选择:
- 写下你自己的看法。可能会复制该 View 的代码以开始使用。
- 修补该 View 以采用额外参数,例如默认为 True 但可以覆盖的“preview_on_errors”。将补丁贡献回 Django,以便其他人可以从中受益。
关于python - django 评论 : how to prevent form errors from redirecting the user to the preview page?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1174140/