即使我关闭了for循环,这个错误也总是出现:
jinja2.exceptions.TemplateSyntaxError: Unexpected end of template. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.
我的python版本是python3.6,flask版本是1.0.6,jinja2版本是2.10
请查看这些代码并帮助我
烧瓶代码:
from flask import *
import pandas
app = Flask(__name__, template_folder='templates')
@app.route('/')
def index():
test = pandas.read_csv('test.csv')
test0 = test['PassengerId']
test1 = test['Name']
print(test0, test1)
return render_template('index.html', tables={'test':test0,'test1':test1})
if __name__ == '__main__':
app.debug = True
app.run()
templates/index.html:
{% block content %}
<head>
<title>pandas app</title>
</head>
{% block body %}
{% for test0,test1 in tables %}
<TABLE>
<thead>
<tr>
<th>PassengerId</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ test0 }}</td>
<td>{{ test1 }}</td>
</tr>
</tbody>
</TABLE>
{% endfor %}
{% endblock %}
{% endblock %}
请帮帮我,感谢您的帮助。
谢谢
发布于 2019-03-04 20:18:02
您可以一次阻止多个块,因此请将它们分开:
{% block content %}
<head>
<title>pandas app</title>
</head>
{% endblock %}
{% block body %}
{% for test0,test1 in tables %}
<TABLE>
<thead>
<tr>
<th>PassengerId</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ test0 }}</td>
<td>{{ test1 }}</td>
</tr>
</tbody>
</TABLE>
{% endfor %}
{% endblock %}
https://stackoverflow.com/questions/54981755
复制相似问题