本文整理汇总了Python中webhelpers.html.HTML.link方法的典型用法代码示例。如果您正苦于以下问题:Python HTML.link方法的具体用法?Python HTML.link怎么用?Python HTML.link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webhelpers.html.HTML
的用法示例。
在下文中一共展示了HTML.link方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stylesheet_link
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import link [as 别名]
def stylesheet_link(*urls, **attrs):
"""Return CSS link tags for the specified stylesheet URLs.
``urls`` should be the exact URLs desired. A previous version of this
helper added magic prefixes; this is no longer the case.
Examples::
>>> stylesheet_link('/stylesheets/style.css')
literal(%(u)s'<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />')
>>> stylesheet_link('/stylesheets/dir/file.css', media='all')
literal(%(u)s'<link href="/stylesheets/dir/file.css" media="all" rel="stylesheet" type="text/css" />')
"""
if "href" in attrs:
raise TypeError("keyword arg 'href' not allowed")
attrs.setdefault("rel", "stylesheet")
attrs.setdefault("type", "text/css")
attrs.setdefault("media", "screen")
tags = []
for url in urls:
tag = HTML.link(href=url, **attrs)
tags.append(tag)
return literal('\n').join(tags)
示例2: onPostListBuilding
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import link [as 别名]
def onPostListBuilding(self, event):
"""
>>> from shimpy.ext.index import PostListBuildingEvent
>>> from shimpy.core.page import Page
>>> from mock import Mock
>>> context.config = {"title": "Site Title"}
>>> ri = RSSImages()
>>> context.page = Page()
>>> ri.onPostListBuilding(PostListBuildingEvent([]))
>>> context.page.html_headers[0]
literal(u'<link href="/rss/images/1" id="images" rel="alternate" title="Site Title - Images" type="application/rss+xml" />')
>>> context.page = Page()
>>> ri.onPostListBuilding(PostListBuildingEvent(["search", "terms"]))
>>> context.page.html_headers[0]
literal(u'<link href="/rss/images/search terms/1" id="images" rel="alternate" title="Site Title - Images with tags: search terms" type="application/rss+xml" />')
"""
title = context.config.get("title")
if event.search_terms:
search = " ".join(event.search_terms)
feed_title = "%s - Images with tags: %s" % (title, search)
link = make_link("rss/images/%s/1" % search)
else:
feed_title = "%s - Images" % title
link = make_link("rss/images/1")
context.page.add_html_header(HTML.link(
id="images", rel="alternate", type="application/rss+xml",
title=feed_title, href=link
))
示例3: auto_discovery_link
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import link [as 别名]
def auto_discovery_link(url, feed_type="rss", **attrs):
"""Return a link tag allowing auto-detecting of RSS or ATOM feed.
The auto-detection of feed for the current page is only for
browsers and news readers that support it.
``url``
The URL of the feed. (This should be the exact URLs desired. A
previous version of this helper added magic prefixes; this is no longer
the case.)
``feed_type``
The type of feed. Specifying 'rss' or 'atom' automatically
translates to a type of 'application/rss+xml' or
'application/atom+xml', respectively. Otherwise the type is
used as specified. Defaults to 'rss'.
Examples::
>>> auto_discovery_link('http://feed.com/feed.xml')
literal(%(u)s'<link href="http://feed.com/feed.xml" rel="alternate" title="RSS" type="application/rss+xml" />')
>>> auto_discovery_link('http://feed.com/feed.xml', feed_type='atom')
literal(%(u)s'<link href="http://feed.com/feed.xml" rel="alternate" title="ATOM" type="application/atom+xml" />')
>>> auto_discovery_link('app.rss', feed_type='atom', title='atom feed')
literal(%(u)s'<link href="app.rss" rel="alternate" title="atom feed" type="application/atom+xml" />')
>>> auto_discovery_link('/app.html', feed_type='text/html')
literal(%(u)s'<link href="/app.html" rel="alternate" title="" type="text/html" />')
"""
if "href" in attrs:
raise TypeError("keyword arg 'href' is not allowed")
if "type" in attrs:
raise TypeError("keyword arg 'type' is not allowed")
title = ""
if feed_type.lower() in ('rss', 'atom'):
title = feed_type.upper()
feed_type = 'application/%s+xml' % feed_type.lower()
attrs.setdefault("title", title)
return HTML.link(rel="alternate", type=feed_type, href=url, **attrs)