本文整理汇总了Python中webhelpers.html.HTML.div方法的典型用法代码示例。如果您正苦于以下问题:Python HTML.div方法的具体用法?Python HTML.div怎么用?Python HTML.div使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webhelpers.html.HTML
的用法示例。
在下文中一共展示了HTML.div方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkbox
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def checkbox(label, name, checked=False, **kwargs):
kwargs['type'] = 'checkbox'
kwargs['name'] = name
if checked:
kwargs['checked'] = 'checked'
kwargs.setdefault('id', name)
return HTML.div(class_='formField checkbox',
id='%s-field' % kwargs['id'],
c=[HTML.label(for_=name, c=[
HTML.input(**kwargs),
HTML.span(class_='labelText', c=[label])
]),
HTML.literal('<form:error name="%s" />' % name)])
示例2: input_area
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def input_area(name, title, value='', cols='50', rows='5', help_text=None, disabled=False, **kwargs):
expl = None
if help_text is not None:
expl = HTML.span(class_='helpText', c=help_text)
if disabled:
kwargs['disabled'] = 'disabled'
kwargs.setdefault('id', name)
return HTML.div(class_='formField',
id='%s-field' % kwargs['id'],
c=[HTML.label(for_=name, c=[
HTML.span(class_='labelText', c=[title]),
HTML.span(class_='textField', c=[
HTML.textarea(name_=name, cols=cols, rows=rows, c=[value], **kwargs),
])]),
HTML.literal('<form:error name="%s" />' % name),
expl])
示例3: select_radio
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def select_radio(name, title, options, selected=[], help_text=None, **kwargs):
expl = None
if help_text is not None:
expl = HTML.span(class_='helpText', c=help_text)
radios = []
for value, label in options:
checked = value in selected
radios.append(radio(name, value, checked, label, **kwargs))
return HTML.div(class_='formField',
id='%s-field' % name,
c=[HTML.label(for_=name, c=[
HTML.span(class_='labelText', c=[title]),
HTML.span(class_='radioField', c=radios)]),
HTML.literal('<form:error name="%s" />' % name),
expl])
示例4: select_line
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def select_line(name, title, options, selected=[], help_text=None, right_next=None, **kwargs):
expl = None
if help_text is not None:
expl = HTML.span(class_='helpText', c=help_text)
next = None
if right_next is not None:
next = HTML.span(class_='rightNext', c=right_next)
kwargs.setdefault('id', name)
field = select(name, selected, options, **kwargs)
return HTML.div(class_='formField',
id='%s-field' % kwargs['id'],
c=[HTML.label(for_=name, c=[
HTML.span(class_='labelText', c=[title]),
HTML.span(class_='textField', c=[
field,
])]),
next,
HTML.literal('<form:error name="%s" />' % name),
expl])
示例5: input_line
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def input_line(name, title, value='', help_text=None, right_next=None, **kwargs):
expl = None
if help_text is not None:
expl = HTML.span(class_='helpText', c=help_text)
next = None
if right_next is not None:
next = HTML.span(class_='rightNext', c=right_next)
kwargs.setdefault('id', name)
kwargs.setdefault('type', 'text')
return HTML.div(class_='formField',
id='%s-field' % kwargs['id'],
c=[HTML.label(for_=name, c=[
HTML.span(class_='labelText', c=[title]),
HTML.span(class_='textField', c=[
HTML.input(value=value, name_=name, **kwargs),
])]),
next,
HTML.literal('<form:error name="%s" />' % name),
expl])
示例6: button_to
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def button_to(name, 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) or 'POST'
url, name = url, name or url
submit_type = html_options.get('type')
img_source = html_options.get('src')
if submit_type == 'image' and img_source:
html_options["value"] = name
html_options.setdefault("alt", name)
else:
html_options["type"] = "submit"
html_options["value"] = name
return HTML.form(method=form_method, action=url, class_="button-to",
c=[HTML.div(method_tag, HTML.input(**html_options))])
示例7: form
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def form(url, method="post", multipart=False, hidden_fields=None, **attrs):
"""An open tag for a form that will submit to ``url``.
You must close the form yourself by calling ``end_form()`` or outputting
</form>.
Options:
``method``
The method to use when submitting the form, usually either
"GET" or "POST". If "PUT", "DELETE", or another verb is used, a
hidden input with name _method is added to simulate the verb
over POST.
``multipart``
If set to True, the enctype is set to "multipart/form-data".
You must set it to true when uploading files, or the browser will
submit the filename rather than the file.
``hidden_fields``
Additional hidden fields to add to the beginning of the form. It may
be a dict or an iterable of key-value tuples. This is implemented by
calling the object's ``.items()`` method if it has one, or just
iterating the object. (This will successfuly get multiple values for
the same key in WebOb MultiDict objects.)
Because input tags must be placed in a block tag rather than directly
inside the form, all hidden fields will be put in a
'<div style="display:none">'. The style prevents the <div> from being
displayed or affecting the layout.
Examples:
>>> form("/submit")
literal(%(u)s'<form action="/submit" method="post">')
>>> form("/submit", method="get")
literal(%(u)s'<form action="/submit" method="get">')
>>> form("/submit", method="put")
literal(%(u)s'<form action="/submit" method="post"><div style="display:none">\\n<input name="_method" type="hidden" value="put" />\\n</div>\\n')
>>> form("/submit", "post", multipart=True)
literal(%(u)s'<form action="/submit" enctype="multipart/form-data" method="post">')
Changed in WebHelpers 1.0b2: add <div> and ``hidden_fields`` arg.
Changed in WebHelpers 1.2: don't add an "id" attribute to hidden tags
generated by this helper; they clash if there are multiple forms on the
page.
"""
fields = []
attrs["action"] = url
if multipart:
attrs["enctype"] = "multipart/form-data"
if method.lower() in ['post', 'get']:
attrs['method'] = method
else:
attrs['method'] = "post"
field = hidden("_method", method, id=None)
fields.append(field)
if hidden_fields is not None:
try:
it = hidden_fields.items()
except AttributeError:
it = hidden_fields
for name, value in it:
field = hidden(name, value, id=None)
fields.append(field)
if fields:
div = HTML.div(style="display:none", _nl=True, *fields)
else:
div = None
return HTML.form(div, _closed=False, **attrs)
示例8: field
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def field(
label='',
field='',
required=False,
label_desc='',
field_desc='',
help='',
error='',
field_pre='',
):
"""\
Format a field with a label.
``label``
The label for the field
``field``
The HTML representing the field, wrapped in ``literal()``
``required``
Can be ``True`` or ``False`` depending on whether the label should be
formatted as required or not. By default required fields have an
asterix.
``label_desc``
Any text to appear underneath the label, level with ``field_desc``
``field_desc``
Any text to appear underneath the field
``help``
Any HTML or JavaScript to appear imediately to the right of the field
which could be used to implement a help system on the form
``error``
Any text to appear immediately before the HTML field, usually used for
an error message.
It should be noted that when used with FormEncode's ``htmlfill`` module,
errors appear immediately before the HTML field in the position of the
``error`` argument. No ``<form:error>`` tags are added automatically by
this helper because errors are placed there anyway and adding the tags
would lead to this helper generating invalid HTML.
``field_pre``
Any HTML to appear immediately above the field.
TIP: For future compatibility, always specify arguments explicitly and do
not rely on their order in the function definition.
Here are some examples:
>>> print field('email >', literal('<input type="text" name="test" value="" />'), required=True)
<tr class="field">
<td class="label" valign="top"><span class="required">*</span><label>email >:</label></td>
<td class="field" colspan="2" valign="top"><input type="text" name="test" value="" /></td>
</tr>
>>> print field(
... label='email >',
... field=literal('<input type="text" name="test" value="" />'),
... label_desc='including the @ sign',
... field_desc='Please type your email carefully',
... error='This is an error message <br />',
... help = 'No help available for this field',
... required=True,
... )
...
<tr class="field">
<td class="label" valign="top"><span class="required">*</span><label>email >:</label></td>
<td class="field" valign="top"><div class="error">This is an error message <br /></div><input type="text" name="test" value="" /></td>
<td class="help" valign="top">No help available for this field</td>
</tr>
<tr class="description">
<td class="label_desc" valign="top"><span class="small">including the @ sign</span></td>
<td class="field_desc" colspan="2" valign="top"><span class="small">Please type your email carefully</span></td>
</tr>
An appropriate stylesheet to use to style forms generated with field() when
the table class is specified as "formbuild" would be::
table.formbuild span.error-message, table.formbuild div.error, table.formbuild span.required {
font-weight: bold;
color: #f00;
}
table.formbuild span.small {
font-size: 85%;
}
table.formbuild form {
margin-top: 20px;
}
table.formbuild form table td {
padding-bottom: 3px;
}
"""
if error:
field = HTML.div(class_='error', c=error)+field
if label:
label = label + literal(':')
if field_pre:
#.........这里部分代码省略.........
示例9: input_wysiwyg
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def input_wysiwyg(name, title, value='', cols='60', rows='15'):
return HTML.div(class_='form-field', c=[
HTML.label(for_=name, c=[title]),
HTML.textarea(class_='ckeditor', name_=name, id_=name, cols=cols, rows=rows, c=[value]),
HTML.literal('<form:error name="%s" />' % name)
])
示例10: input_hidden
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import div [as 别名]
def input_hidden(name, value='', **kwargs):
kwargs.setdefault('id', name)
return HTML.div(class_='formField',
id='%s-field' % kwargs['id'],
c=[HTML.input(type='hidden', value=value, name_=name, **kwargs),
HTML.literal('<form:error name="%s" />' % name)])