[Django]-Django use value of template variable as part of another variable name

4👍

First, you would need a custom template filter to mimic getattr() functionality, see:

Then, you would need add template filter for string concatenation:

{% load getattribute %}

{% for i in 1234|make_list %}    
    {% with "answer_"|add:i as answer %}
        {{ form|getattribute:answer }}
    {% endwith %}
{% endfor %}
👤alecxe

Leave a comment