Django的评论应用程序的自定义模板不显示字段

时间:2010-03-25 13:36:57

标签: django templates django-comments

我想在博客应用程序中使用django.contrib.comments并自定义表单的显示方式。我的问题是我无法显示字段,虽然显示隐藏的字段工作得很好。我查看了文档,并将其与显示表单的常规方式进行了比较,但老实说,我不知道为什么以下内容无效:

{% 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> 
你能告诉我我做错了什么吗?提前致谢

1 个答案:

答案 0 :(得分:2)

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

form.fields是一个字典,其中键是字段的名称,值是实际的form.Field()个对象。

您还可以执行{% for field in form %},其中应包括隐藏和可见字段。