本文整理匯總了Python中webhelpers2.html.HTML.link方法的典型用法代碼示例。如果您正苦於以下問題:Python HTML.link方法的具體用法?Python HTML.link怎麽用?Python HTML.link使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webhelpers2.html.HTML
的用法示例。
在下文中一共展示了HTML.link方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: stylesheet_link
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.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'<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />')
>>> stylesheet_link('/stylesheets/dir/file.css', media='all')
literal(u'<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: link_css_url
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import link [as 別名]
def link_css_url(self, url, **kwargs):
if not kwargs.pop('relative_path', False):
url = abs_static_url(url)
else:
url = static_url(url)
link_tag = HTML.link(rel='stylesheet', type='text/css', href=url, **kwargs)
self.data['x-link-tags'].append(link_tag)
return u''
示例3: auto_discovery_link
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.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'<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'<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'<link href="app.rss" rel="alternate" title="atom feed" type="application/atom+xml" />')
>>> auto_discovery_link('/app.html', feed_type='text/html')
literal(u'<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)