python - html 中的 CherryPy 变量

标签 python cherrypy

我有一个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/

相关文章:

javascript - Python 与 javascript 列表

python - 如何将 Opencv 集成到 Tkinter 窗口中

python - 字典键 : custom objects vs lists

python - Pandas - 仅删除等于零的连续行

error-handling - Pyramid Cherrpy空白错误页面

python - cherrypy https 脚本不适用于 linux 启动

python - 如何在不同的变量中存储小数点之前和之后的数字。 PYTHON

python - 在 CherryPy 中提供静态目录

python - MySQL+Python 索引超出范围错误

python - CherryPy + Werkzeug 调试器?