Reputation: 33
So during the following bottle server route everything works fine...
@route('/IFC/config/<policy>')
def config(policy):
if policy == "test":
html_nodes = ""
Nodes = IFC_main.get_nodes(ipaddr,username,password)
for node in Nodes:
html_nodes += '<li>'+node["name"]+'</li>'
return template("mgmt.tpl",html_nodes = html_nodes)
except when I look at the source code for the webpage that this produces it should be a dropdown menu with the values I provided but instead I get this...
<script language="JavaScript" type="text/javascript" src="/static/mgmt.js"> </script>
<link rel="stylesheet" type="text/css" href="/static/mgmt.css">
<body style = "background-color:#CCCCCA">
<img id="banner" style = "bg-color:CBCCCE" src="static/Cisco_emailHeader.png" alt="Banner Image"/>
<div style="width: 800px;height: 100px;position: absolute;top:0;bottom: 0;left: 0;right: 0;margin: auto;">
<h1>Management Connectivity</h1>
<ul class="dropdown-menu">
<li>calo2-leaf3</li><li>calo2- spine1</li><li>calo2-leaf2</li><li>calo2- leaf1</li><li>apic2</li><li>calo2- spine2</li><li>apic1</li><li>apic3</li>
</ul>
</div>
</body>
I understand I need to convert the string I'm passing into the template but I just haven't been able to figure out what. I'm assuming someone else has ran into this issue.
Upvotes: 1
Views: 137
Reputation: 143
You can start the statement with an exclamation mark to disable escaping for that statement:
>>> template('Hello {{name}}!', name='<b>World</b>')
u'Hello <b>World</b>!'
>>> template('Hello {{!name}}!', name='<b>World</b>')
u'Hello <b>World</b>!'
Upvotes: 2
Reputation: 4467
You need to move the loop into template file,
% for node in nodes:
<li>{{ node.name }}</li>
% end
The code will change to,
@route('/IFC/config/<policy>')
def config(policy):
if policy == "test":
nodes = IFC_main.get_nodes(ipaddr,username,password)
return template("mgmt.tpl", nodes=nodes)
Upvotes: 1