from jinja2 import FileSystemLoader, Environment
import os
curr_dir = os.path.dirname(os.path.abspath(__file__)) #указываем что шаблон находится в корне
env = Environment(loader=FileSystemLoader(curr_dir))
template = env.get_template('1.html')
q=[] # список кокторый заполняется
...
with open("index.html", "w", encoding='utf-8') as f:
f.write(template.render(q=q))
{% for i in q%}
<tr>
<td><a href="{{i[0]}}">{{i[0]}}</a></td>
<td>{{i[1]}}</td>
<td>{{i[2]}}</td>
<td>{{i[3]}}</td>
</tr>
{%endfor%}
>>> from jinja2 import Template
>>> template = Template("""
... <table style="border:2px black solid">
... <tr>
... {% for item in my_array %}
... <td>{{item}}</td>
... {% endfor %}
... </tr>
... </table>""")
>>> my_array = range(10)
>>> my_array
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> print(template.render(my_array=my_array))
<table style="border:2px black solid">
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
>>>