title: Django/Python: Loop over selected form fields in Django template
body: <p>I have a form with n fields. The first 4 fields should be displayed differently in my template then the rest of the form. Therefore, I was wondering if I can somehow loop over the first 4 fields, end the loop and continue looping over the rest of the fields later in the template.</p>
  
  <pre><code>        &lt;table&gt;
              {% for field in form %}
              {% if forloop.counter == 4 &lt;&lt;&lt; Break here &gt;&gt;&gt;%}
              &lt;tr&gt;
                  &lt;td&gt; {{ field.label_tag }} &lt;/td&gt;
                  &lt;td&gt; {{ field }} &lt;/td&gt;
              &lt;/tr&gt;
              {% endfor %}
          &lt;/table&gt;
          .... Different code ....
          &lt;table&gt;
              {% for field in form %} &lt;&lt;&lt; Continue here &gt;&gt;&gt;
              &lt;tr&gt;
                  &lt;td&gt; {{ field.label_tag }} &lt;/td&gt;
                  &lt;td&gt; {{ field }} &lt;/td&gt;
              &lt;/tr&gt;
              {% endfor %}
          &lt;/table&gt;
  </code></pre>
  
  <p>I have found <a href="http://djangosnippets.org/snippets/2093/" rel="nofollow">this code</a> but I was wondering if I could structure the template differently or if I have missed some new changes in Django 1.3 which allow the breaking of loops now.</p>
  
  <p>Normally, I would split the form in two seperate forms, but I would like to reuse the form definition in other templates as well, therefore I would like to keep all information together in one form.</p>
  
  <p>Thank you for your advice!</p>