python - 在mako模板: call python function within html string中

标签 python cherrypy mako

如何在 mako 中执行此操作:

<% import cherrypy %>
...
<link rel="stylesheet" href="${cherrypy.url('/media/layout.css')}" type="text/css" />

AttributeError: 'Undefined' object has no attribute 'url'

最佳答案

答案:而不是 <% import cherrypy %>一个需要<%! import cherrypy %>

关于python - 在mako模板: call python function within html string中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4007898/

相关文章:

django - Mako csrf_token 就像 Django 模板中一样

python - 使用 Python Bottle 的 Webhelpers

python - 如何连接到 boto3 中的区域

Python修改生成器

python - 使用 mako 模板处理 404 错误

Python CherryPy 调用 HTML 文件

python - 如何验证字符串并将其转换为特定格式python

python - 如何计算python列表中的连续重复项

python - CherryPy 和 RESTful 网络 API

python /灰鲭鲨 : How to get unicode strings/characters parsed correctly?