我正在使用flak和jinja2来模板继承。我知道这个错误。
jinja2.exceptions.TemplateSyntaxError: Unexpected end of template. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'.
python代码
from flask import *
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/bear.html')
def bear():
return render_template('bear.html')
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=2092)
Html代码库
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<link rel="stylesheet" href="index.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="index.html"><img src="book.svg"/> Encyclopedia</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</div>
</nav>
</head>
<body>
<div class="frontpanel">
{% block img %}
{% endblock %}
<P>
KINGDOM
{% block kingdom %}
{% endblock %}
<br>
PHYLUM
{% block phylum %}
{% endblock %}
<br>
SUBPHYLUM
{% block subphylum %}
{% endblock %}
<br>
CLASS
{% block class %}
{% endblock %}
<br>
ORDER
{% block order %}
{% endblock %}
<br>
SUBORDER
{% block suborder %}
{% endblock %}
<br>
FAMILY
{% block family %}
{% endblock %}
<br>
GENUS
{% block genus %}
{% endblock %}
<br>
SPECIES
{% block species %}
{% endblock %}
</P>
</div>
<table>
<tr>
<th>Information</th>
<th></th>
</tr>
<tr>
<td>Population size</td>
<td>lifespan</td>
<td>Top Speed</td>
<td>Weight</td>
<td>Height</td>
<td>Length</td>
</tr>
<tr>
<td>{% block population %}
{% endblock %}</td>
<td>{% block lifespan %}
{% endblock %}</td>
<td>{% block topspeed %}
{% endblock %}</td>
<td>{% block weight %}
{% endblock %}</td>
<td>{% block height %}
{% endblock %}</td>
<td>{% block length %}
{% endblock %}</td>
</tr>
</table>
<p>{% block body %}
{% endblock %}</p>
<P>CONTINENTS
{% block continents %}
{% endblock %}
<br>
SUBCONTINENTS
{% block subcontinents %}
{% endblock %}
<br>
COUNTRIES
{% block countries %}
{% endblock %}
<br>
BIOGEOGRAPHICAL REALMS
{% block realms %}
{% endblock %}
</P>
</body>
</html>
第二个HTML
{% extends "base.html" %}
{% block img %}
<img src="https://animalia.us-east-1.linodeobjects.com/animals/photos/full/1.25x1/DQjvOrjwumEpEyBEaJtX.jpg">
{endblock}
{% block kingdom %}
Animalia
{% endblock %}
{% block phylum %}
Chordata
{% endblock %}
{% block subphylum %}
Vertebrata
{% endblock %}
{% block class %}
Mammalia
{% endblock %}
{% block order %}
Carnivora
{% endblock %}
{% block suborder %}
Mammalia
{% endblock %}
{% block family %}
Ursidae
{% endblock %}
{% block genus %}
Ursus
{% endblock %}
{% block species %}
Ursus arctos
{% endblock %}
{% block population %}
200 000
{% endblock %}
{% block lifespan %}
20-50 Years
{% endblock %}
{% block topspeed %}
56 KM/H
{% endblock %}
{% block weight %}
100-635 KG
{% endblock %}
{% block height %}
70-153 cm
{% endblock %}
{% block length %}
1.4-2.8 M
{% endblock %}
{% block body %}
The Brown bear is a large mammal with a notable hump of muscles over its shoulders. This animal is the second largest species of bear. The legs of Brown bear are strong with huge paws. Their claws are rather long on their front feet, allowing them to dig their dens as well as dig for food. The ears are relatively small and the face is concave while the head is large with powerful jaws. Brown bears have ability of standing and walking on their hind legs; they do so in order to determine location of a food source or to identify a threat. These animals have thick coat, varying in color from black to brown and blonde. The guard hair of these animals is longer, sometimes having white tip, which gives them grizzled appearance.
{% endblock %}
{% block continents %}
Asia, Europe, North America
{% endblock %}
{% block subcontinents %}
South Asia, Western Asia, East Asia, Central Asia, Southeast Asia
{% endblock %}
{% block countries %}
Albania, Armenia, Austria, Azerbaijan, Belarus, Bosnia and Herzegovina, Bulgaria, Canada, China, Croatia, Estonia, Finland, France, Georgia, Greece, India, Iran, Iraq, Italy, Japan, Kazakhstan, North Korea, Kyrgyzstan, Latvia, Macedonia, Mongolia, Montenegro, Nepal, Norway, Pakistan, Poland, Romania, Russia, Serbia, Slovakia, Slovenia, Spain, Sweden, Tajikistan, Turkey, Ukraine, United States, Uzbekistan, Bhutan, Lebanon, Afghanistan
{% endblock %}
发布于 2022-05-22 19:16:00
在第二行html的第二行中,有一个类似于此{endblock}
的端点块,这可能会导致错误,因为它是一个语法错误。修改它为{% endblock %}
,它应该是好的!
https://stackoverflow.com/questions/72340218
复制相似问题