我正在尝试显示我的基本模板中的值,以便在单击标记时显示在子模板(placenamelist.html)中,但是无法识别这些值,它只是按原样打印。我已经将我的基本模板扩展到了孩子,但它仍然无效。我从python循环通过oracle使用jinja2渲染父模板,但子模板不呈现for循环值
Jinja模板
def getMarkers():
conn = cx_Oracle.connect(dsn="sgen", user="s14346", password=pw)
c = conn.cursor()
c.execute("SELECT A.PLACENAME_ID, A.OLD_NAME, DBMS_LOB.substr(A.SUPPLEMENTARY,3000), B.ICON_PATH \n, A.DESCRIPTION, A.LATITUDE, A.LONGITUDE FROM PLACENAMES A, ICONS B WHERE A.ICON_ID = B.ICON_ID ORDER BY PLACENAME_ID")
markers = []
for row in c:
markers.append([row[0],row[1],row[2],row[3],row[4], row[5], row[6]])
conn.close
return markers
def render_site(base_template):
env = Environment(loader=FileSystemLoader('../jinja'))
template = env.get_template('placenamelist.html')
return template.render(base_template='test_template.html', markers=markers)
markers = getMarkers()
print(render_site('test_template.html'))
Base_template
{% for item in markers %}
var marker{{ item[0] }} = L.marker({{ item[5:] }});
// Create an element to hold all your text and markup
var popup{{ item[0] }} = $('<div/>');
// Delegate all event handling for the container itself and its contents to the container
popup{{item[0]}}.on('click', '.special', function (){
var url = "http://www.geos.ed.ac.uk/~s1774346/jinja/placenamelist.html#"+{{item[0]}};
open(url);
event.preventDefault();
});
// Insert whatever you want into the container, using whichever approach you prefer
popup{{item[0]}}.html(("<table height='90'><tr><td>{{ item[1] }}</td></tr><tr><td align='center'><b><i>{{ item[4] }}</b></i></td></tr><tr><td align='center'><button class='special'><img src='../icon/contract.svg' height=30 width=30 /></button></td></tr></table>"));
// Insert the container into the popup
marker{{ item[0] }}.bindPopup(popup{{ item[0] }}[0]);
markers.addLayer(marker{{ item[0] }});
map.addLayer(markers)
{% endfor %}
儿童模板(placenamelist.html)
Content-Type: text/html
{% extends base_template %}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="https://www.geos.ed.ac.uk/~s14346/stylesheet.css">
</head>
<body>
<table>
{% for item in markers %}
<tr><td>{{ item[2] }} </td></tr>
{% endfor %}
</table>
</body>