python - Django use value of template variable as part of another variable name -
i have loop inside template:
{% in 1234|make_list %}
i obtain inside loop:
{{ form.answer_{{ }} }}
i aware above line not valid (it raises templatesyntaxerror), know if there way use value of part other variable name.
first, need custom template filter mimic getattr()
functionality, see:
then, need add
template filter string concatenation:
{% load getattribute %} {% in 1234|make_list %} {% "answer_"|add:i answer %} {{ form|getattribute:answer }} {% endwith %} {% endfor %}
Comments
Post a Comment