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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -