Search code examples
pythonhtmljinja2

Jinja using input dictionary value in loop not working


I am using Flask to build a Python web frontend. I have a Jinja2 template that is taking a dictionary of inputs called result, and building HTML output. In the code below, I am able to hardcode a range, but not use a value of result['n'] as you can see in the code. I've seen other people do basically the same thing and it works. Because I am using Google Cloud, I'm not seeing error messages, it just isn't working

<!doctype html>
{{result['n']}}
<table border = 1>
{% for i in range(result['n']) %}
    <tr>
    {% for j in range(3) %}
    <td>1</td>
    </tr>
    {% endfor %}
{% endfor %}
</table>

I've tried setting a variable with {%set n = result['n'] %} but this isn't working either


Solution

  • it needs a str->int conversion, like this: result['n']|int