我有一个cherryPy 程序,它返回一个表格中包含图像(绘图)的页面。我还想在表中添加描述情节的变量。我没有使用任何模板只是想让它变得非常简单。在下面的示例中,我在想要的位置有变量 numberofapplicants,但它不会输出表中变量的值。我无法找到任何如何执行此操作的示例。 感谢您的帮助 文森特
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>
'''
最佳答案
假设您使用的是 Python 2.x,只需使用常规字符串格式即可。
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}
关于python - html 中的 CherryPy 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1610995/