2010-03-25 63 views
0

我想在博客應用程序中使用django.contrib.comments並自定義表單的顯示方式。我的問題是,我不能讓字段顯示,雖然顯示隱藏的領域工作得很好。我有一個看看文檔,並與顯示形式的常規方式相比,但老實說,我不知道爲什麼下面不工作了:Django評論應用程序的自定義模板不顯示字段

{% get_comment_form for comments_object as form %} 
<form action="{% comment_form_target %}" method="POST"> 
[…] 
{% for hidden in form.hidden_fields %} 
     {{ hidden }} 
    {% endfor %} 
    {% for field in form.fields %} 
     {{field}} 
    {% endfor %} 
[…] 
</form> 

輸出看起來是這樣的:

<form action="/comments/post/" method="POST"> 
      <input type="hidden" name="content_type" value="flatpages.flatpage" id="id_content_type" />   
      <input type="hidden" name="object_pk" value="1" id="id_object_pk" /> 
      <input type="hidden" name="timestamp" value="1269522506" id="id_timestamp" />    
      <input type="hidden" name="security_hash" value="ec4…0fd" id="id_security_hash" /> 
      content_type 
      object_pk 
      timestamp 
      security_hash 
      name 
      email 
      url 
      comment 
      honeypot 
     […] 
    </form> 
</div> 

你能告訴我我做錯了什麼嗎?在此先感謝

回答

2

使用{% for field in form.visible_fields %}

form.fields是一本字典,其中鍵是字段的名稱,和值是實際form.Field()對象。

你也可以做{% for field in form %}它應該包括隱藏和可見的領域。

+0

感謝您澄清此問題 – jnns 2010-03-26 17:10:46