How to make flask jinja use variables from python list as a jinja expression variables
<p>So I have a list:</p>

<pre><code>ABC = ['{{ row[0] }}','{{ row[1] }}','{{ row[2] }}']
</code></pre>

<p>In HTML template, I want to use each items in list ABC as Jinja expression, how can i do it, here is my HTML table template</p>

<pre><code>{% for row in reports %}
    &lt;tr&gt;
    {% for item in ABC %}
        &lt;td&gt;{{ item }}&lt;/td&gt;
    {% endfor %}
    &lt;/tr&gt;
{% endfor %}
</code></pre>

<p>I tried to remove {{ }} from each item in ABC list, but it didn't work. It seemed like each item in HTML template was treated as a string, can't use by each row in reports.</p>

<p>In HTML page, the table render like this:</p>

<p>Column1      | Column2      | Column3</p>

<p>{{ row[0] }} | {{ row[1] }} | {{ row[2] }}</p>

<p>I want it work like this.</p>

<pre><code>{% for row in reports %}
    &lt;tr&gt;
        &lt;td&gt;{{ row[0] }}&lt;/td&gt;
        &lt;td&gt;{{ row[1] }}&lt;/td&gt;
        &lt;td&gt;{{ row[2] }}&lt;/td&gt;
    &lt;/tr&gt;
{% endfor %}
</code></pre>

<p>Edit: I have change to another solution.</p>

<p>The problem is how you are creating the list. Right now you're giving it strings that identify the items you want to output. Instead, give it what you want to output. </p>

<pre><code>ABC = [row[0], row[1], row[2]]
</code></pre>

<p>Edit: Since you are trying to print all of the columns in the template you can just iterate over them there. </p>

<pre><code>{% for column in row %}
    &lt;td&gt;{{ column }}&lt;/td&gt;
{% endfor %}
</code></pre>

python python-3.x flask jinja2