django评论:如何防止表单错误将用户重定向到预览页面?

Tee*_*bes 7 python django django-contrib

目前,如果表单上有任何错误,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, {})
    )
Run Code Online (Sandbox Code Playgroud)

有没有什么办法可以在不将源代码更改为django.contrib.comments的情况下更改此行为?

任何指针都会被赞赏......

谢谢!

Ste*_*osh 3

看起来你有两个真正的选择:

  • 写出你自己的看法。可以复制该视图的代码来开始。
  • 修补该视图以采用额外参数,例如“preview_on_errors”,默认为 True 但可以覆盖。将补丁贡献回 Django,以便其他人可以从中受益。