本文整理汇总了Python中webhelpers.html.HTML.img方法的典型用法代码示例。如果您正苦于以下问题:Python HTML.img方法的具体用法?Python HTML.img怎么用?Python HTML.img使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webhelpers.html.HTML
的用法示例。
在下文中一共展示了HTML.img方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display_image
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import img [as 别名]
def display_image(self, page, post):
img = HTML.img(
alt="main image",
class_="shm-main-image",
id="main_image",
src=post.image_url,
data_width=post.width,
data_height=post.height,
)
context.page.add_block(Block("Image", img, "main", 10))
示例2: test_html
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import img [as 别名]
def test_html():
a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag")
eq_(a,
u'<a href="http://mostlysafe" <tag">Bad <script> tag</a>')
img = HTML.img(src='http://some/image.jpg')
eq_(img, u'<img src="http://some/image.jpg" />')
br = HTML.br()
eq_(u'<br />', br)
示例3: image
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import img [as 别名]
def image(url, alt, width=None, height=None, **attrs):
"""Return an image tag for the specified ``source``.
``url``
The URL of the image. (This must be the exact URL desired. A
previous version of this helper added magic prefixes; this is
no longer the case.)
``alt``
The img's alt tag. Non-graphical browsers and screen readers will
output this instead of the image. If the image is pure decoration
and uninteresting to non-graphical users, pass "". To omit the
alt tag completely, pass None.
``width``
The width of the image, default is not included
``height``
The height of the image, default is not included
Examples::
>>> image('/images/rss.png', 'rss syndication')
literal(u'<img alt="rss syndication" src="/images/rss.png" />')
>>> image('/images/xml.png', "")
literal(u'<img alt="" src="/images/xml.png" />')
>>> image("/images/icon.png", height=16, width=10, alt="Edit Entry")
literal(u'<img alt="Edit Entry" height="16" src="/images/icon.png" width="10" />')
>>> image("/icons/icon.gif", alt="Icon", width=16, height=16)
literal(u'<img alt="Icon" height="16" src="/icons/icon.gif" width="16" />')
>>> image("/icons/icon.gif", None, width=16)
literal(u'<img alt="" src="/icons/icon.gif" width="16" />')
"""
if not alt:
alt = ""
if width is not None:
attrs['width'] = width
if height is not None:
attrs['height'] = height
return HTML.img(src=url, alt=alt, **attrs)
示例4: image
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import img [as 别名]
def image(url, alt, width=None, height=None, path=None, use_pil=False,
**attrs):
"""Return an image tag for the specified ``source``.
``url``
The URL of the image. (This must be the exact URL desired. A
previous version of this helper added magic prefixes; this is
no longer the case.)
``alt``
The img's alt tag. Non-graphical browsers and screen readers will
output this instead of the image. If the image is pure decoration
and uninteresting to non-graphical users, pass "". To omit the
alt tag completely, pass None.
``width``
The width of the image, default is not included.
``height``
The height of the image, default is not included.
``path``
Calculate the width and height based on the image file at ``path`` if
possible. May not be specified if ``width`` or ``height`` is
specified. The results are also written to the debug log for
troubleshooting.
``use_pil``
If true, calcuate the image dimensions using the Python Imaging
Library, which must be installed. Otherwise use a pure Python
algorithm which understands fewer image formats and may be less
accurate. This flag controls whether
``webhelpers.media.get_dimensions_pil`` or
``webhelpers.media.get_dimensions`` is called. It has no effect if
``path`` is not specified.
Examples::
>>> image('/images/rss.png', 'rss syndication')
literal(%(u)s'<img alt="rss syndication" src="/images/rss.png" />')
>>> image('/images/xml.png', "")
literal(%(u)s'<img alt="" src="/images/xml.png" />')
>>> image("/images/icon.png", height=16, width=10, alt="Edit Entry")
literal(%(u)s'<img alt="Edit Entry" height="16" src="/images/icon.png" width="10" />')
>>> image("/icons/icon.gif", alt="Icon", width=16, height=16)
literal(%(u)s'<img alt="Icon" height="16" src="/icons/icon.gif" width="16" />')
>>> image("/icons/icon.gif", None, width=16)
literal(%(u)s'<img alt="" src="/icons/icon.gif" width="16" />')
"""
if not alt:
alt = ""
if width is not None or height is not None:
attrs['width'] = width
attrs['height'] = height
if path:
raise TypeError(
"can't specify path if width and height are specified")
elif path:
if use_pil:
result = media.get_dimensions_pil(path)
msg = "using PIL"
else:
result = media.get_dimensions(path)
msg = "not using PIL"
abspath = os.path.abspath(path)
log.debug("image size is %s for '%s' (%s)", result, abspath, msg)
attrs['width'] = result[0]
attrs['height'] = result[1]
return HTML.img(src=url, alt=alt, **attrs)
示例5: get_avatar_html
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import img [as 别名]
def get_avatar_html(self, size=80):
av = self.get_avatar_url(size)
if av:
return HTML.img(src=av, width=size, height=size)
else:
return ""