【问题标题】:Django: Comment post not allowed (400) ErrorDjango:不允许发表评论(400)错误
【发布时间】:2011-07-11 01:19:29
【问题描述】:

我正在尝试在我的 Web 应用程序上使用 django cmets,但出现此错误:

不允许发表评论 (400) 原因:缺少 content_type 或 object_pk 字段。

我正在使用以下表格:

<form action="{% comment_form_target %}" method="POST">
        {% for field in form %}
        {% if field.is_hidden %}
        {{ field }}
        {% endif %}
        {% endfor %}
        <input type="hidden" name="name" value="{{ user }}" />
        <input type="text" name="honeypot" size="64" style="display: none;" />
        <textarea id="id_comment" rows="1" cols="40"
                  name="comment"></textarea>
        <input type="submit" name="submit" class="submit-post" value="Post" />
</form>

但是当我使用 django 自动生成的表单时

{% render_comment_form for event %}

一切正常。问题是,我不想要 Name/E-Mail/etc.-Input 字段。只有评论文本区域。有人可以帮我解决这个问题吗?

问候

【问题讨论】:

    标签: django


    【解决方案1】:

    错误消息非常清楚:您在呈现表单时可能未能包含content_typeobject_pk。检查您呈现的表单是否具有这些字段。或许看完Notes on the comment form你会发现问题所在。

    【讨论】:

    • 感谢您的回答!我再次检查文档。我意识到当我想加载自定义表单时,我忘记将 {% get_comment_form for [object] 添加为 [varname] %}。
    猜你喜欢
    • 1970-01-01
    • 2016-06-17
    • 2021-04-19
    • 2018-05-29
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多