本文整理匯總了Python中webhelpers2.html.HTML.label方法的典型用法代碼示例。如果您正苦於以下問題:Python HTML.label方法的具體用法?Python HTML.label怎麽用?Python HTML.label使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webhelpers2.html.HTML
的用法示例。
在下文中一共展示了HTML.label方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: radio
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import label [as 別名]
def radio(name, value, checked=False, label=None, **attrs):
"""Create a radio button.
Arguments:
``name`` -- the field's name.
``value`` -- the value returned to the application if the button is
pressed.
``checked`` -- true if the button should be initially pressed.
``label`` -- a text label to display to the right of the button.
The id of the radio button will be set to the name + '_' + value to
ensure its uniqueness. An ``id`` keyword arg overrides this. (Note
that this behavior is unique to the ``radio()`` helper.)
To arrange multiple radio buttons in a group, see
webhelpers2.containers.distribute().
"""
_set_input_attrs(attrs, "radio", name, value)
if checked:
attrs["checked"] = "checked"
if not "id" in attrs:
attrs["id"] = '%s_%s' % (name, _make_safe_id_component(value))
widget = HTML.input(**attrs)
if label:
widget = HTML.label(widget, label)
return widget
示例2: title
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import label [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")
示例3: checkbox
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import label [as 別名]
def checkbox(name, value="1", checked=False, label=None, id=NotGiven, **attrs):
"""Create a check box.
Arguments:
``name`` -- the widget's name.
``value`` -- the value to return to the application if the box is checked.
``checked`` -- true if the box should be initially checked.
``label`` -- a text label to display to the right of the box.
``id`` is the HTML ID attribute, and should be passed as a keyword
argument. By default the ID is the same as the name filtered through
``_make_safe_id_component()``. Pass None to suppress the
ID attribute entirely.
The following HTML attributes may be set by keyword argument:
* ``disabled`` - If true, checkbox will be grayed out.
* ``readonly`` - If true, the user will not be able to modify the checkbox.
To arrange multiple checkboxes in a group, see
webhelpers2.containers.distribute().
Example::
>>> checkbox("hi")
literal(u'<input id="hi" name="hi" type="checkbox" value="1" />')
"""
_set_input_attrs(attrs, "checkbox", name, value)
_set_id_attr(attrs, id, name)
if checked:
attrs["checked"] = "checked"
convert_boolean_attrs(attrs, ["disabled", "readonly"])
widget = HTML.input(**attrs)
if label:
widget = HTML.label(widget, label)
return widget