Q:

In Django, how to use a list from html checkboxes to loop through elements, and go to element specific page

I want to obtain a list from a HTML form with specific IDs in it:
search.html:
<form method='POST' action='/report/'>
{% for o in obj %}
    <tbody>
    <tr>
      <td>{{o.sample}}</td>
      <td><input type="checkbox" name="Samples" value="{{o.sample}}</td>
    </tr>
    </tbody>
{% endfor %}
<input type="submit" value="Submit">
</form>

This gives me a list of samples to my report view which takes me to /report/
in my URLs i have defined a regex so that it would be able to take me to a sample specific report URL:
url(r'^report/Sam\d{1,5}_\d{2}/$', views.report),

What I want is to be able to loop through this list sample IDs, so when I click the initial submit, it takes me to the first sample ID at:
localhost:8000/report/H1_1/

then I process and make a report for this sample, I submit and it takes me to the next sample ID in my list:
localhost:8000/report/H2_1/

etc.
I have been racking my brain on how to do this and the only thing I came up with was:
search.html:
{% for o in obj %}
    <form method='POST' action='/report/{{o.sample}}'>
    <tbody>
    <tr>
      <td>{{o.sample}}</td>
      <td><input type="checkbox" name="Samples" value="{{o.sample}}</td>
    </tr>
    </tbody>
{% endfor %}
<input type="submit" value="Submit">
</form>

but I cant work how to get to the next sample in the sample specific html page form. 

A:

You probably want to close every form inside the loop, or you want a single form with all the entry, but what you have now is not so clean and could lead to errors.
Something like this:
{% for o in obj %}
<form method="POST" action="/report/{{o.sample}}">
    <tbody>
        <tr>
            <td>{{o.sample}}</td>
            <td><input type="checkbox" name="Samples" value="{{o.sample}}"></td>
        </tr>
    </tbody>
    <input type="submit" value="Submit" label="Submit {{o.sample}}">
</form>
{% endfor %}

Or like this for a single form:
<form method="POST" action="/report/samples">
{% for o in obj %}
    <tbody>
        <tr>
            <td>{{o.sample}}</td>
            <td><input type="checkbox" name="Samples" value="{{o.sample}}"></td>
        </tr>
    </tbody>
{% endfor %}
<input type="submit" value="Submit" label="Submit">
</form>

But I think, based on what you wrote, that the 1st example better fits your needs.

