本文整理匯總了Python中webhelpers2.html.HTML.span方法的典型用法代碼示例。如果您正苦於以下問題:Python HTML.span方法的具體用法?Python HTML.span怎麽用?Python HTML.span使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webhelpers2.html.HTML
的用法示例。
在下文中一共展示了HTML.span方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: title
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import span [as 別名]
def title(title, required=False, label_for=None):
"""Format the user-visible title for a form field.
Use this for forms that have a text title above or next to each
field.
``title`` -- the name of the field; e.g., "First Name".
``required`` -- if true, append a \*" to the title and use the
'required' HTML format (see example); otherwise use the 'not
required' format.
``label_for`` -- if provided, put ``<label for="ID">`` around the
title. The value should be the HTML ID of the input field related
to this title. Per the HTML standard, the ID should point to a
single control (input, select, textarea), not to multiple controls
(fieldset, group of checkboxes, group of radio buttons). ID's are
set by passing the keyword arg ``id`` to the appropriate helper.
Note that checkboxes and radio buttions typically have their own
individual labels in addition to the title. You can set these with
the ``label`` argument to ``checkbox()`` and ``radio()``.
This helper does not accept other keyword arguments.
See webhepers2/static/stylesheets/webhelpers2.css for suggested styles.
>>> title("First Name")
literal(u'<span class="not-required">First Name</span>')
>>> title("Last Name", True)
literal(u'<span class="required">Last Name <span class="required-symbol">*</span></span>')
>>> title("First Name", False, "fname")
literal(u'<span class="not-required"><label for="fname">First Name</label></span>')
>>> title("Last Name", True, label_for="lname")
literal(u'<span class="required"><label for="lname">Last Name</label> <span class="required-symbol">*</span></span>')
"""
title_html = title
required_html = literal("")
if label_for:
title_html = HTML.label(title_html, for_=label_for)
if required:
required_symbol = HTML.span("*", class_="required-symbol")
return HTML.span(
title_html,
" ",
required_symbol,
class_="required")
else:
return HTML.span(title_html, class_="not-required")
示例2: required_legend
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import span [as 別名]
def required_legend():
"""Return an inline HTML snippet explaining which fields are required.
See webhepers/static/stylesheets/webhelpers2.css for suggested styles.
>>> required_legend()
literal(u'<span class="required required-symbol">*</span> = required')
"""
return HTML(
HTML.span("*", class_="required required-symbol"),
" = required",
)
示例3: test_tag_with_data_attr
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import span [as 別名]
def test_tag_with_data_attr(self):
assert HTML.span(data_foo="bar") == literal('<span data-foo="bar"></span>')