Search code examples
pythoncherrypymako

In mako template: call python function within html string


How do I do this in mako:

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

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

Solution

  • Answer: Instead of <% import cherrypy %> one needs <%! import cherrypy %>