django: form.fields not iterating through instance fields

后端 未结 3 1167
梦如初夏
梦如初夏 2020-12-10 09:00

I am trying to iterate through form.fields in a template and for:

{% for field in form.fields %}
   {{ field }}, 
{% endfor %}

I am getting

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 09:40

    Iterating "form" instead over "form.fields" solved the problem. Not sure why as the documentation also provides examples such as:

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

    which also results in empty sets. Has to do with the fact that my form is not bound? not sure...

提交回复
热议问题