Cheetah 中的未绑定/绑定方法

发布于 2024-09-08 06:20:18 字数 820 浏览 2 评论 0原文

有没有办法在猎豹中声明静态方法? 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖果控 2024-09-15 06:20:18

此页面似乎有一些相关信息,但我不在现在我自己尝试一下,抱歉。

具体来说,您应该能够执行以下操作:

#@staticmethod
#def address($address, $title)

...并使其正常工作。

(如果您不知道, 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:

#@staticmethod
#def address($address, $title)

...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".)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文