I have template like this:
{% for a in As%}
<div>blah--blah--</div>
<input type="hidden" name="doSomeThingTarget" value={{a.xx}}>
<input type="hidden" name="submit" value="doSomeThing">
{% endfor%}
The loop may execute couple of times, and show some submit buttons.
In python file, I code:
target = self.request.get('doSomeThingTarget')
You know, I try to use value={{a.xx}} to hold the value in a particular loop, so, when I click one of the buttons, I can figure out what’s target I need to process. BUT whichever I click, I just get the value of the first loop. What’s wrong with my code? How can I implement my intention?
Thank you.
You’re defining a single form, with multiple copies of a hidden input element with the same name. As a result, you only get the one copy (though if you used
get_all, you’d get an array of all of them).Instead, you should include the form start and end tags inside the loop, making each iteration its own form.