staticpages.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:zing 作者: evernote 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号