开发者

Un/bound methods in Cheetah

开发者 https://www.devze.com 2023-01-06 09:49 出处:网络
Is there a way to declare static methods in cheetah? IE snippets.tmpl #def address($address, $title) <div class=\"address\">

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)?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消