本文整理匯總了Python中coffin.template.Library.object方法的典型用法代碼示例。如果您正苦於以下問題:Python Library.object方法的具體用法?Python Library.object怎麽用?Python Library.object使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類coffin.template.Library
的用法示例。
在下文中一共展示了Library.object方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Library
# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import object [as 別名]
from coffin.template import Library
from jinja2.runtime import Undefined
# from jinja2 import Markup
from jinja2 import filters
register = Library()
def url(view_name, *args, **kwargs):
"""This is an alternative to the {% url %} tag. It comes from a time
before Coffin had a port of the tag.
"""
from coffin.template.defaulttags import url
return url._reverse(view_name, args, kwargs)
register.jinja2_filter(url, jinja2_only=True)
register.object(url)
@register.jinja2_filter(jinja2_only=True)
def timesince(value, *arg):
if value is None or isinstance(value, Undefined):
return u''
from django.utils.timesince import timesince
return timesince(value, *arg)
@register.jinja2_filter(jinja2_only=True)
def timeuntil(value, *args):
if value is None or isinstance(value, Undefined):
return u''
from django.utils.timesince import timeuntil
return timeuntil(value, *args)
示例2: hello_func
# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import object [as 別名]
"""Register a Jinja2 global object with a Coffin library object.
"""
def hello_func(name):
return u"Hello %s" % name
from coffin.template import Library
register = Library()
register.object('hello', hello_func)