所以,我使用django.contrib.comments。我已經安裝了它,但不是笨重的默認評論表單,我想使用一個只顯示textarea和提交按鈕的自定義表單模板。定製django評論
這背後的基本原理是,用戶只能看到表單,如果他們的區域已經過身份驗證,我想保持簡單的表單,並自動拿起他們的用戶名等。
我已經實現了一個自定義表單,但是當我嘗試提交時出現錯誤。
下面是我在我與評論表單的頁面模板(條目從視圖中傳遞的對象):
{% load comments %}
{% render_comment_form for entry %}
這是我的HTML中/templates/comments/form.html:
{% if user.is_authenticated %}
<p>Submit a comment:</p>
<form action="/comments/post/" method="post">
<textarea name="comment" id="id_comment" rows="2" style="width: 90%;"></textarea>
<input type="hidden" name="options" value="{{ options }}" />
<input type="hidden" name="target" value="{{ target }}" />
<input type="hidden" name="gonzo" value="{{ hash }}" />
<input type="hidden" name="next" value="{{ entry.get_absolute_url }}" />
<span style="float:right;"><input type="submit" name="post" value="Add"></span>
</form>
{% else %}
<p>Please <a href="/login/">log in</a> to post a comment.</p>
{% endif %}
它呈現好的開始,但是當我嘗試提交評論的形式,我得到以下的Django錯誤:
Comment post not allowed (400)
Why: Missing content_type or object_pk field.
任何人都可以幫忙嗎?