本文整理汇总了Python中django.template.base.Library.simple_tag方法的典型用法代码示例。如果您正苦于以下问题:Python Library.simple_tag方法的具体用法?Python Library.simple_tag怎么用?Python Library.simple_tag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.base.Library
的用法示例。
在下文中一共展示了Library.simple_tag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: force_text
# 需要导入模块: from django.template.base import Library [as 别名]
# 或者: from django.template.base.Library import simple_tag [as 别名]
"""
try:
import markdown2
except ImportError:
logging.warning("Markdown package not installed.")
return force_text(value)
else:
def parse_extra(extra):
if ':' not in extra:
return (extra, {})
name, values = extra.split(':', 1)
values = dict((str(val.strip()), True) for val in values.split('|'))
return (name.strip(), values)
extras = (e.strip() for e in arg.split(','))
extras = dict(parse_extra(e) for e in extras if e)
if 'safe' in extras:
del extras['safe']
safe_mode = True
else:
safe_mode = False
return mark_safe(markdown2.markdown(force_text(value), extras=extras, safe_mode=safe_mode))
register.simple_tag(takes_context=True)(static)
register.simple_tag(takes_context=True)(url)
register.simple_tag(takes_context=True)(config)
register.simple_tag(takes_context=True)(current_page)
register.simple_tag(takes_context=True)(if_current_page)
示例2: Library
# 需要导入模块: from django.template.base import Library [as 别名]
# 或者: from django.template.base.Library import simple_tag [as 别名]
# with Crate these terms will supersede the license and you may use the
# software solely pursuant to the terms of the relevant commercial agreement.
__docformat__ = "reStructuredText"
import json
import datetime
from django.template.base import Library
from django.utils.safestring import mark_safe
register = Library()
CDN_URL = 'https://crate.io'
def media(context, media_url):
"""
Get the path for a media file.
"""
if media_url.startswith('http://') or media_url.startswith('https://'):
url = media_url
elif media_url.startswith('/'):
url = u'{0}{1}'.format(CDN_URL, media_url)
else:
url = u'{0}/media/{1}'.format(CDN_URL, media_url)
return url
register.simple_tag(takes_context=True)(media)