代码之家  ›  专栏  ›  技术社区  ›  colinmarc

Cheetah中的unbound方法

  •  0
  • colinmarc  · 技术社区  · 16 年前

    有没有一种方法可以在cheetah中声明静态方法?IE公司

    #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
    

    其他.tmpl

    #from snippets import *
    
    $snippets.address($home_address, "home address")
    

    NotFound: cannot find 'address' . Cheetah将其编译为绑定方法,natch:

    代码段.py

    class snippets(Template):
    
        ...
    
        def address(self, address, title, **KWS):
    

    有没有一种方法可以声明静态方法?如果不是,有哪些替代方法可以实现这样的功能(代码段库)?

    1 回复  |  直到 16 年前
        1
  •  0
  •   detly    16 年前

    This page 好像有一些相关的信息,但是我现在不能自己去试试,对不起。

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

    (如果你不知道, staticmethod 是一个内置函数,用于创建。。。静态方法:)它最常用作 decorator . 所以我通过google找到了那个页面” cheetah staticmethod ".)

    推荐文章