【问题标题】:Custom template for Django's comments application does not display fieldsDjango 评论应用的自定义模板不显示字段
【发布时间】:2010-03-25 13:36:56
【问题描述】:

我想在博客应用程序中使用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> 

你能告诉我我做错了什么吗?提前致谢

【问题讨论】:

    标签: django templates django-comments


    【解决方案1】:

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

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

    您也可以使用{% for field in form %},其中应包括隐藏和可见字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      • 2014-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多