当前位置: 首页>>代码示例>>Python>>正文


Python HTML.button方法代码示例

本文整理汇总了Python中webhelpers.html.HTML.button方法的典型用法代码示例。如果您正苦于以下问题:Python HTML.button方法的具体用法?Python HTML.button怎么用?Python HTML.button使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webhelpers.html.HTML的用法示例。


在下文中一共展示了HTML.button方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: input_submit_text_button

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import button [as 别名]
def input_submit_text_button(text=None, name=None, **html_options):
    if text is None:
        from pylons.i18n import _
        text = _('Save')
    if name is not None:
        html_options['name'] = name

    html_options.setdefault('class_', "btn-text")
    html_options.setdefault('value', text)
    return HTML.button(c=[HTML.span(text)], **html_options)
开发者ID:nous-consulting,项目名称:ututi,代码行数:12,代码来源:helpers.py

示例2: input_submit

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import button [as 别名]
def input_submit(text=None, name=None, **kwargs):
    if text is None:
        from pylons.i18n import _
        text = _('Save')
    if name is not None:
        kwargs['name'] = name

    if 'class_' in kwargs:
        kwargs['class_'] += ' submit'
    else:
        kwargs['class_'] = 'submit'
    kwargs.setdefault('value', text)
    return HTML.button(c=text, **kwargs)
开发者ID:nous-consulting,项目名称:ututi,代码行数:15,代码来源:helpers.py

示例3: submit

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import button [as 别名]
def submit(label, **attrs):
    attrs['class'] = 'btn action save'    
    return HTML.button(literal('<span><span>' + label + '</span></span>'), **attrs)    
开发者ID:rafal-kos,项目名称:pytis,代码行数:5,代码来源:helpers.py

示例4: button_to

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import button [as 别名]
def button_to(title, url='', **html_options):
    """Generate a form containing a sole button that submits to
    ``url``.

    Use this method instead of ``link_to`` for actions that do not have
    the safe HTTP GET semantics implied by using a hypertext link.

    The parameters are the same as for ``link_to``.  Any
    ``html_options`` that you pass will be applied to the inner
    ``input`` element. In particular, pass

        disabled = True/False

    as part of ``html_options`` to control whether the button is
    disabled.  The generated form element is given the class
    'button-to', to which you can attach CSS styles for display
    purposes.

    The submit button itself will be displayed as an image if you
    provide both ``type`` and ``src`` as followed:

         type='image', src='icon_delete.gif'

    The ``src`` path should be the exact URL desired.  A previous version of
    this helper added magical prefixes but this is no longer the case.

    Example 1::

        # inside of controller for "feeds"
        >> button_to("Edit", url(action='edit', id=3))
        <form method="POST" action="/feeds/edit/3" class="button-to">
        <div><input value="Edit" type="submit" /></div>
        </form>

    Example 2::

        >> button_to("Destroy", url(action='destroy', id=3),
        .. method='DELETE')
        <form method="POST" action="/feeds/destroy/3"
         class="button-to">
        <div>
            <input type="hidden" name="_method" value="DELETE" />
            <input value="Destroy" type="submit" />
        </div>
        </form>

    Example 3::

        # Button as an image.
        >> button_to("Edit", url(action='edit', id=3), type='image',
        .. src='icon_delete.gif')
        <form method="POST" action="/feeds/edit/3" class="button-to">
        <div><input alt="Edit" src="/images/icon_delete.gif"
         type="image" value="Edit" /></div>
        </form>

    .. note::
        This method generates HTML code that represents a form. Forms
        are "block" content, which means that you should not try to
        insert them into your HTML where only inline content is
        expected. For example, you can legally insert a form inside of
        a ``div`` or ``td`` element or in between ``p`` elements, but
        not in the middle of a run of text, nor can you place a form
        within another form.
        (Bottom line: Always validate your HTML before going public.)

    """

    if html_options:
        convert_boolean_attrs(html_options, ['disabled'])

    method_tag = ''
    method = html_options.pop('method', '')
    if method.upper() in ['PUT', 'DELETE']:
        method_tag = HTML.input(
            type='hidden', id='_method', name_='_method', value=method)

    form_method = (method.upper() == 'GET' and method.lower()) or 'post'

    url, title = url, title or url

    html_options.setdefault('class_', "btn")

    submit_type = html_options.get('type')
    img_source = html_options.get('src')
    if submit_type == 'image' and img_source:
        html_options["value"] = title
        html_options.setdefault("alt", title)
        button_element = HTML.input(**html_options)
    else:
        html_options["type"] = "submit"
        html_options["value"] = title
        button_element = HTML.button(c=[HTML.span(title)], **html_options)

    return HTML.form(method=form_method, action=url, class_="button-to",
                     c=[HTML.fieldset(c=[method_tag, button_element])])
开发者ID:nous-consulting,项目名称:ututi,代码行数:98,代码来源:helpers.py


注:本文中的webhelpers.html.HTML.button方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。