2010-10-24 69 views
2

內蟒功能如何做到這一點的灰鯖:在鯖模板:調用HTML字符串

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

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

您是否嘗試過引進別的東西,如數學? >>> t =模板('<%import math%>結果:$ {math.sqrt(9)}') >>> t.render() '結果:3.0' – atomocopter 2010-10-24 11:26:11

+1

我明白了:您需要'<%! ... %>' – tauran 2010-10-24 11:41:20

+0

@atomocopter如果你把這個解決方案寫成一個正確的答案,那麼tauran可以接受它,並且以後的用戶不需要通過評論來尋找解決方案(並且你在這個過程中獲得了一些東西);) – 2010-10-24 11:52:13

回答

3

答:不是的<% import cherrypy %>一個需要<%! import cherrypy %>