All,
How Can we increment a value like the following in django templates,
{{ flag =0 }}
{% for op in options %}
{{op.choices}}<input type="radio" name="template" id="template" value="template{{flag++}}"/>
{% endfor %}
thanks..
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think it’s intended you should alter data in your templates. For in your specific case, you could instead use the
forloop.countervariable.For example:
Also note that I added that number to the
idattributes of the<input />tag. Otherwise you’ll have multiple inputs with the same id.EDIT: I didn’t note that it was a radio input. You could of course have the same name for each
<input type="radio" />.