我正在研究需要登录的flask-sqlalchemy webapp。 仅当用户登录时,才应在页面上显示注销按钮。 所以这些页面扩展了layout.html文件,如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Login</title>
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
{% block head %} {% endblock %}
</head>
<body>
{% block body %}
<style type="text/css">
#footer {
position : absolute;
bottom : 0;
}
</style>
{ % if session['logged_in'] %}
<div id="footer" style="width:300px;height:100px"><a href=" {{url_for('logout')}}" style="width:100%;background:#f1f1f1;">Logout</a></div>
{% endif %}
{% endblock %}
<script src="{{ url_for('static', filename='js/jquery.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
</body>
</html>
我得到的错误是:
TemplateSyntaxError:遇到未知标签'endif'。金贾是 寻找以下标签:'endblock'。
需要关闭的最里面的块是'block'。
虽然已指定了endblock和if标签 请帮我解决这个问题
答案 0 :(得分:2)
尝试删除{和%in
之间的空格function createOrderStatuses(){
var access_token = BCAPI.Helper.Site.getAccessToken();
var request = $.ajax({
url: "/webresources/api/v3/sites/current/orderstatuses",
type: "GET",
connection: "keep-alive",
contentType: "application/json",
headers: _authorization
});
request.done(function (msg) {
console.log(msg);
//var orderStatusesArray = msg[];
for (var i = 0; i < msg.items.length; i++){
var statuses = msg.items[i];
var statusTemplate = '<div class="large-12 columns margin-distributed statusClass" id="'+ statuses.id +'"><h4 class="lato-bold">' + statuses.label + '</h4></div>';
if (statuses.label !== "EXCHANGE FEE PAID"){
$("#ordersContainer").append(statusTemplate);
}else{
//$(".orderStatuses").append('<option value="'+ statuses.id +'">' + statuses.label + '</option>');
}
}//looping and displaying statuses
getOrders();
});//request END
function getOrders(){
var access_token = BCAPI.Helper.Site.getAccessToken();
var request = $.ajax({
url: "/webresources/api/v3/sites/current/orders",
type: "GET",
connection: "keep-alive",
contentType: "application/json",
headers: _authorization
});
request.done(function (msg) {
console.log(msg);
var containerID = $('.statusClass').each(function(){ $(this).attr('id'); });
for (var i = 0; i < msg.items.length; i++){
var orders = msg.items[i];
var orderTemplate = '<div class="large-12 columns margin-distributed '+ orders.statusTypeId +'"><h5>' + orders.name + '</h5></div>';
var orderTemplateClass = orderTemplate.find('div[class*="'+orders.statusTypeId+'"]');
if ( orderTemplateClass === containerID ){
$(containerID).append(orderTemplate);
}// end IF
}//looping orders
});
}//GET ORDERS END
}
createOrderStatuses();
这样就变成了
{ % if session['logged_in'] %}