jinja2.exceptions.TemplateSyntaxError в jinja (цикл не завершен, хотя я написал {% endfor%} в коде) - PullRequest
0 голосов
/ 04 марта 2019

эта ошибка всегда появляется, даже если я закрыл цикл 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, версия на фляге - 1.0.6 и версия на jinja 2 - 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 %}

пожалуйста, помогите мне, любая помощь приветствуется

спасибо

1 Ответ

0 голосов
/ 04 марта 2019

Вы можете заблокировать несколько блоков одновременно, поэтому разделите их:

{% 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 %}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...