【问题标题】:Django: empty comment form error handlingDjango:空注释表单错误处理
【发布时间】:2013-02-16 00:51:55
【问题描述】:

我使用标准的 django cmets 框架。

模板:

<h2>Add comment</h2> {%  get_comment_form for post as form %} 
<form  action="{% comment_form_target %}" method="post" > {% csrf_token %}   
{{form.content_type}}{{form.object_pk}}{{form.timestamp}}{{form.security_hash}}
Comment:<br />
{{form.comment}}

<input type="hidden" name="next" value="{{ request.get_full_path }}#comment" /> 

<button class="btn btn-large btn-primary" type="submit">Post</button>

</form>

网址:

(r'^comments/', include('django.contrib.comments.urls')),

然后我发送空表单,我重定向到 /cmets/post/ 页面。 我怎样才能重新加载当前页面并添加错误消息?谢谢!

【问题讨论】:

    标签: django forms redirect comments


    【解决方案1】:

    这是正确的行为。见&lt;form action="{% comment_form_target %}" method="post"&gt;?您的表单提交到 url /comments/post/ 页面,因此即使它是空白的,您也会最终到达那里。您需要做的是向/comments/post/ 的视图添加某种处理,这会将您重定向到原始页面,并在表单不完整或不正确时告诉用户填写表单。不过Django通常会这样做,所以我不知道这里有什么不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-18
      • 2016-06-08
      • 2012-07-24
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多