CherryPy variables in html
I have a cherryPy program that returns a page that has an image (graph) in a table. I would also like to have variables in the table that describe the graph. I am not using templates, just trying to keep them very simple. In the example below, I have the variable numberofapplicants where I want, but it does not output the value of the variable in the table. I have not been able to find examples on how to do this. Thanks for your help Vincent
return '''
<html>
<body>
<table width="400" border="1">
<tr>
<td>numberofapplicants</td>
</tr>
<tr>
<td width="400" height="400"><img src="img/atest.png" width="400" height="400" /></td>
</tr>
</table>
</body>
</html>
'''
+2
source to share
2 answers
Assuming you are using Python 2.x, just use standard string formatting.
return '''
<html>
<body>
<table width="400" border="1">
<tr>
<td>%(numberofapplicants)s</td>
</tr>
<tr>
<td width="400" height="400"><img src="img/atest.png" width="400" height="400" /></td>
</tr>
</table>
</body>
</html>
''' % {"numberofapplicants": numberofapplicants}
+2
source to share