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


Python CharField.widget_attrs方法代码示例

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


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

示例1: test_charfield_widget_attrs

# 需要导入模块: from django.forms import CharField [as 别名]
# 或者: from django.forms.CharField import widget_attrs [as 别名]
    def test_charfield_widget_attrs(self):
        """
        CharField.widget_attrs() always returns a dictionary (#15912).
        """
        # Return an empty dictionary if max_length is None
        f = CharField()
        self.assertEqual(f.widget_attrs(TextInput()), {})
        self.assertEqual(f.widget_attrs(Textarea()), {})

        # Otherwise, return a maxlength attribute equal to max_length
        f = CharField(max_length=10)
        self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10'})
        self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'})
        self.assertEqual(f.widget_attrs(Textarea()), {'maxlength': '10'})
开发者ID:277800076,项目名称:django,代码行数:16,代码来源:test_charfield.py

示例2: test_charfield_widget_attrs

# 需要导入模块: from django.forms import CharField [as 别名]
# 或者: from django.forms.CharField import widget_attrs [as 别名]
    def test_charfield_widget_attrs(self):
        """
        CharField.widget_attrs() always returns a dictionary and includes
        minlength/maxlength if min_length/max_length are defined on the field
        and the widget is not hidden.
        """
        # Return an empty dictionary if max_length and min_length are both None.
        f = CharField()
        self.assertEqual(f.widget_attrs(TextInput()), {})
        self.assertEqual(f.widget_attrs(Textarea()), {})

        # Return a maxlength attribute equal to max_length.
        f = CharField(max_length=10)
        self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10'})
        self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'})
        self.assertEqual(f.widget_attrs(Textarea()), {'maxlength': '10'})

        # Return a minlength attribute equal to min_length.
        f = CharField(min_length=5)
        self.assertEqual(f.widget_attrs(TextInput()), {'minlength': '5'})
        self.assertEqual(f.widget_attrs(PasswordInput()), {'minlength': '5'})
        self.assertEqual(f.widget_attrs(Textarea()), {'minlength': '5'})

        # Return both maxlength and minlength when both max_length and
        # min_length are set.
        f = CharField(max_length=10, min_length=5)
        self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10', 'minlength': '5'})
        self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10', 'minlength': '5'})
        self.assertEqual(f.widget_attrs(Textarea()), {'maxlength': '10', 'minlength': '5'})
        self.assertEqual(f.widget_attrs(HiddenInput()), {})
开发者ID:CrazyChief,项目名称:django,代码行数:32,代码来源:test_charfield.py

示例3: test_charfield_widget_attrs

# 需要导入模块: from django.forms import CharField [as 别名]
# 或者: from django.forms.CharField import widget_attrs [as 别名]
    def test_charfield_widget_attrs(self):
        """
        CharField.widget_attrs() always returns a dictionary (#15912).
        """
        # Return an empty dictionary if max_length and min_length are both None.
        f = CharField()
        self.assertEqual(f.widget_attrs(TextInput()), {})
        self.assertEqual(f.widget_attrs(Textarea()), {})

        # Return a maxlength attribute equal to max_length.
        f = CharField(max_length=10)
        self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10'})
        self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'})
        self.assertEqual(f.widget_attrs(Textarea()), {'maxlength': '10'})

        # Return a minlength attribute equal to min_length.
        f = CharField(min_length=5)
        self.assertEqual(f.widget_attrs(TextInput()), {'minlength': '5'})
        self.assertEqual(f.widget_attrs(PasswordInput()), {'minlength': '5'})
        self.assertEqual(f.widget_attrs(Textarea()), {'minlength': '5'})

        # Return both maxlength and minlength when both max_length and
        # min_length are set.
        f = CharField(max_length=10, min_length=5)
        self.assertEqual(f.widget_attrs(TextInput()), {'maxlength': '10', 'minlength': '5'})
        self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10', 'minlength': '5'})
        self.assertEqual(f.widget_attrs(Textarea()), {'maxlength': '10', 'minlength': '5'})
开发者ID:2015E8007361074,项目名称:django,代码行数:29,代码来源:test_charfield.py


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