本文整理匯總了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)