python - django 评论 : how to prevent form errors from redirecting the user to the preview page?

标签 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, {})
    )

有什么方法可以在不将源代码更改为 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/

相关文章:

django - 如何在 Django 应用程序中接收 RabbitMQ 消息? ( celery ?)

django - 在 Django 中扩展一个 contrib 模型的字段

python - 如何让 Django Cache Machine 在 django.contrib.auth.models.User 上工作?

python - 运行 manage.py 测试时 django.contrib.messages.tests 中的虚假故障

python - 启用 scrapy 记录器时如何查看打印语句的输出

python - 查找具有多个 'child' 对象的 Django 模型记录?

Django分页...切片页面以显示总页面的一部分?

python - 一个应该用 Python 写出所有正确括号的程序

python - 按频率对 str 系列进行排序

python - 如何删除 0 的转换 pandas 数据帧以记录