I've found myself recently adding a method to my form classes (I use a
common base class) so that I can iterate over only the visible fields:
def visible_fields(self):
"""
Returns a list of BoundField objects that are not marked as
hidden.
"""
return [field for field in self if not field.is_hidden]
Then, where you've written {% for field in form %}, I write
{% for field in form.visible_fields %}
I also have a hidden_fields() method (which is almost identical to the
above) so that I can then include all the hidden fields in the final
form as well. I've used this on two recent projects I've worked on where
I have some custom form layout requirements and want to do it in the
template, rather than via a Python method.
Regards,
Malcolm