def staticpage_url(parser, token):
"""Returns the internal URL for a static page based on its virtual path.
Syntax::
{% staticpage_url 'virtual/path' %}
"""
bits = token.split_contents()
syntax_message = ("%(tag_name)s expects a syntax of %(tag_name)s "
"'virtual/path'" %
dict(tag_name=bits[0]))
quote_message = "%s tag's argument should be in quotes" % bits[0]
if len(bits) == 2:
virtual_path = bits[1]
if (not (virtual_path[0] == virtual_path[-1] and
virtual_path[0] in ('"', "'"))):
raise template.TemplateSyntaxError(quote_message)
return StaticPageURLNode(virtual_path[1:-1])
raise template.TemplateSyntaxError(syntax_message)
评论列表
文章目录