我有如下的HTML代码:
<html>
<head>
<title>Booking Lah</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
.card {
height: 450px;
}
.card-image {
max-height: 300px;
max-width: 350px;
width: auto;
vertical-align: middle;
}
.image-display {
height: 300px;
width: auto;
}
.helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.image-caption {
height: 100px;
}
.star {
color: orange;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="home.php">Booking Lah</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="register.php"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="login.php"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
{{% for row in rows %}}
<div class="col-sm-4 card">
<div class="image-display">
<center>
<span class="helper"></span><img src="{{row['imgurl']}}" class="card-image"><br>
</center>
</div>
<div class="image-caption">
<center>
<h1><a href="#">{{row["name"]}}</a></h1>
<h2>
<span class="glyphicon glyphicon-star star"></span>
</h2>
</center>
</div>
</div>
{{% endfor %}}
</div>
</div>
</body>
</html>
我收到了这样的错误:
jinja2.exceptions.TemplateSyntaxError
TemplateSyntaxError:意外的'%'
模板中的文件“ /home/m26415086/UHTOS/templates/home.html”,第55行
{{%为行中的%%}}
我已经尽力了,但没有任何改变。
最佳答案
在模板中,您使用的是{{%
和%}}
而不是{%
和%}
。{%
用于指令(循环,条件等),而{{
用于替换。这是doc供进一步参考。
关于python - 如何解决jinja2.exceptions.TemplateSyntaxError?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44351786/