【问题标题】:In mako template: call python function within html string在 mako 模板中:在 html 字符串中调用 python 函数
【发布时间】:2011-04-29 19:18:08
【问题描述】:

我如何在 mako 中做到这一点:

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

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

【问题讨论】:

  • 您是否尝试过导入其他内容,例如数学? >>> t = Template('Result: ${math.sqrt(9)}') >>> t.render() 'Result: 3.0'
  • 我知道了:你需要&lt;%! ... %&gt;
  • @atomocopter 你把那个解决方案写成一个正确的答案怎么样,然后 tauran 可以接受它,以后用户不必通过 cmets 来找到解决方案(你在这个过程中会有所收获); )

标签: python cherrypy mako


【解决方案1】:

答案:需要&lt;%! import cherrypy %&gt;而不是&lt;% import cherrypy %&gt;

【讨论】:

    猜你喜欢
    • 2011-06-12
    • 1970-01-01
    • 2011-04-24
    • 2011-11-18
    • 2013-03-28
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多