Custom template for Django's comments application does not display fields
I want to use django.contrib.comments
in a blogging application and customize the way the form is displayed. My problem is that I can't get the fields to display although displaying the hidden fields works just fine. I had a look at the docs and compared it with the regular way of displaying forms but honestly I don't know why the following doesn't work out:
{% get_comment_form for comments_object as form %}
<form action="{% comment_form_target %}" method="POST">
[…]
{% for h开发者_如何学运维idden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% for field in form.fields %}
{{field}}
{% endfor %}
[…]
</form>
The output looks like this:
<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>
Can you tell me what I'm doing wrong? Thanks in advance
use {% for field in form.visible_fields %}
form.fields
is a dictionary where the keys are the names of the fields, and the values are the actual form.Field()
objects.
You can also do {% for field in form %}
which should include both hidden and visible fields.
精彩评论