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

Popular posts from this blog

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -