本文整理汇总了Python中django.forms.widgets.Input方法的典型用法代码示例。如果您正苦于以下问题:Python widgets.Input方法的具体用法?Python widgets.Input怎么用?Python widgets.Input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.widgets
的用法示例。
在下文中一共展示了widgets.Input方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_layout
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Input [as 别名]
def render_layout(self, form, context, template_pack=TEMPLATE_PACK):
"""
Copy any field label to the ``placeholder`` attribute.
Note, this method is called when :attr:`layout` is defined.
"""
# Writing the label values into the field placeholders.
# This is done at rendering time, so the Form.__init__() could update any labels before.
# Django 1.11 no longer lets EmailInput or URLInput inherit from TextInput,
# so checking for `Input` instead while excluding `HiddenInput`.
for field in form.fields.values():
if field.label and \
isinstance(field.widget, (Input, forms.Textarea)) and \
not isinstance(field.widget, forms.HiddenInput):
field.widget.attrs['placeholder'] = u"{0}:".format(field.label)
return super(CompactLabelsCommentFormHelper, self).render_layout(form, context, template_pack=template_pack)
示例2: __init__
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Input [as 别名]
def __init__(self, *args, **kwargs):
super(BootsrapForm, self).__init__(*args, **kwargs)
for field in self.fields.values():
# Only tweak the field if it will be displayed
if not isinstance(field.widget, widgets.HiddenInput):
attrs = {}
if (
isinstance(field.widget, (widgets.Input, widgets.Select, widgets.Textarea)) and
not isinstance(field.widget, (widgets.CheckboxInput,))
):
attrs['class'] = "form-control"
if isinstance(field.widget, (widgets.Input, widgets.Textarea)) and field.label:
attrs["placeholder"] = field.label
if field.required:
attrs["required"] = "required"
field.widget.attrs.update(attrs)
示例3: test_no_trailing_newline_in_attrs
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Input [as 别名]
def test_no_trailing_newline_in_attrs(self):
self.check_html(Input(), 'name', 'value', strict=True, html='<input type="None" name="name" value="value">')
示例4: test_attr_false_not_rendered
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Input [as 别名]
def test_attr_false_not_rendered(self):
html = '<input type="None" name="name" value="value">'
self.check_html(Input(), 'name', 'value', html=html, attrs={'readonly': False})
示例5: test_attrs_with_type
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Input [as 别名]
def test_attrs_with_type(self):
attrs = {'type': 'date'}
widget = Input(attrs)
self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value">')
# reuse the same attrs for another widget
self.check_html(Input(attrs), 'name', 'value', '<input type="date" name="name" value="value">')
attrs['type'] = 'number' # shouldn't change the widget type
self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value">')
示例6: test_custom_widget_kwarg
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Input [as 别名]
def test_custom_widget_kwarg(self):
"""The widget can be overridden with a kwarg."""
field = forms.JSONField(widget=widgets.Input)
self.assertIsInstance(field.widget, widgets.Input)
示例7: test_custom_widget_attribute
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import Input [as 别名]
def test_custom_widget_attribute(self):
"""The widget can be overridden with an attribute."""
class CustomJSONField(forms.JSONField):
widget = widgets.Input
field = CustomJSONField()
self.assertIsInstance(field.widget, widgets.Input)