Cheetah 中的未绑定/绑定方法
有没有办法在猎豹中声明静态方法? IE
snippets.tmpl
#def address($address, $title)
<div class="address">
<b>$title</h1></b>
#if $address.title
$address.title <br/>
#end if
$address.line1 <br/>
#if $address.line2
$address.line2 <br/>
#end if
$address.town, $address.state $address.zipcode
</div>
#end def
....
other snippets
other.tmpl
#from snippets import *
$snippets.address($home_address, "home address")
此代码报告此错误:NotFound:找不到“地址”
。 Cheetah 正在将其编译为绑定方法,natch:
snippets.py
class snippets(Template):
...
def address(self, address, title, **KWS):
有没有办法声明静态方法?如果没有,有哪些替代方法可以实现类似的功能(片段库)?
Is there a way to declare static methods in cheetah? IE
snippets.tmpl
#def address($address, $title)
<div class="address">
<b>$title</h1></b>
#if $address.title
$address.title <br/>
#end if
$address.line1 <br/>
#if $address.line2
$address.line2 <br/>
#end if
$address.town, $address.state $address.zipcode
</div>
#end def
....
other snippets
other.tmpl
#from snippets import *
$snippets.address($home_address, "home address")
This code reports this error: NotFound: cannot find 'address'
. Cheetah is compiling it as a bound method, natch:
snippets.py
class snippets(Template):
...
def address(self, address, title, **KWS):
Is there a way to declare static methods? If not, what are some alternative ways to implement something like this (a snippets library)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此页面似乎有一些相关信息,但我不在现在我自己尝试一下,抱歉。
具体来说,您应该能够执行以下操作:
...并使其正常工作。
(如果您不知道, staticmethod 是一个内置函数,创建一个...静态方法:)它最常用作装饰器。所以我通过谷歌搜索“cheetah staticmethod”找到了该页面。)
This page seems to have some relevant information, but I'm not in a position to try it out myself right now, sorry.
Specifically, you should just be able to do:
...and have it work.
(If you didn't know, staticmethod is a built-in function that creates a... static method :) It's most commonly used as a decorator. So I found that page by Googling "cheetah staticmethod".)