本文整理汇总了Python中django.forms.URLField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.URLField方法的具体用法?Python forms.URLField怎么用?Python forms.URLField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms
的用法示例。
在下文中一共展示了forms.URLField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_urlfield_2
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def test_urlfield_2(self):
f = URLField(required=False)
self.assertEqual('', f.clean(''))
self.assertEqual('', f.clean(None))
self.assertEqual('http://example.com', f.clean('http://example.com'))
self.assertEqual('http://www.example.com', f.clean('http://www.example.com'))
with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
f.clean('foo')
with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
f.clean('http://')
with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
f.clean('http://example')
with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
f.clean('http://example.')
with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
f.clean('http://.com')
示例2: test_urlfield_9
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def test_urlfield_9(self):
f = URLField()
urls = (
'http://עברית.idn.icann.org/',
'http://sãopaulo.com/',
'http://sãopaulo.com.br/',
'http://пример.испытание/',
'http://مثال.إختبار/',
'http://例子.测试/',
'http://例子.測試/',
'http://उदाहरण.परीक्षा/',
'http://例え.テスト/',
'http://مثال.آزمایشی/',
'http://실례.테스트/',
'http://العربية.idn.icann.org/',
)
for url in urls:
with self.subTest(url=url):
# Valid IDN
self.assertEqual(url, f.clean(url))
示例3: make_entry_field
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def make_entry_field(self, fieldsubmission=None):
c = forms.URLField(required=self.config['required'],
label=self.config['label'],
help_text=self.config['help_text'])
if fieldsubmission:
c.initial = fieldsubmission.data['info']
return c
示例4: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def __init__(self, verbose_name=None, name=None, **kwargs):
kwargs['max_length'] = kwargs.get('max_length', 200)
super(URLField, self).__init__(verbose_name, name, **kwargs)
示例5: deconstruct
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def deconstruct(self):
name, path, args, kwargs = super(URLField, self).deconstruct()
if kwargs.get("max_length", None) == 200:
del kwargs['max_length']
return name, path, args, kwargs
示例6: formfield
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def formfield(self, **kwargs):
# As with CharField, this will cause URL validation to be performed
# twice.
defaults = {
'form_class': forms.URLField,
}
defaults.update(kwargs)
return super(URLField, self).formfield(**defaults)
示例7: formfield
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def formfield(self, **kwargs):
# As with CharField, this will cause URL validation to be performed
# twice.
defaults = {
'form_class': forms.URLField,
}
defaults.update(kwargs)
return super().formfield(**defaults)
示例8: formfield
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def formfield(self, **kwargs):
# As with CharField, this will cause URL validation to be performed
# twice.
return super().formfield(**{
'form_class': forms.URLField,
**kwargs,
})
示例9: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def __init__(self, required=True, help_text=None, max_length=None, min_length=None, validators=(), **kwargs):
self.field = forms.URLField(
required=required,
help_text=help_text,
max_length=max_length,
min_length=min_length,
validators=validators,
)
super().__init__(**kwargs)
示例10: test_url_field
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def test_url_field(self):
data = self.get_form_field_data("url")
cls = wsf_fields.URLField()
field = cls.get_formfield(data)
self.assertIsInstance(field, forms.URLField)
self.assertIsInstance(field.widget, forms.widgets.URLInput)
self.assertEqual(field.label, data["label"])
self.assertEqual(field.required, data["required"])
self.assertEqual(field.help_text, data["help_text"])
self.assertEqual(field.initial, data["default_value"])
示例11: deconstruct
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def deconstruct(self):
name, path, args, kwargs = super(URLField, self).deconstruct()
if kwargs.get("max_length") == 200:
del kwargs['max_length']
return name, path, args, kwargs
示例12: test_should_url_convert_string
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def test_should_url_convert_string():
assert_conversion(forms.URLField, String)
示例13: _clean_url
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def _clean_url(url):
url_field = URLField()
return url_field.clean(url.strip())
示例14: get_form_field
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def get_form_field(self, **kwargs):
"""Return a Django form field appropriate for a URL property.
This defaults to a URLField instance.
"""
defaults = {'form_class': forms.URLField}
defaults.update(kwargs)
return super(LinkProperty, self).get_form_field(**defaults)
示例15: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import URLField [as 别名]
def __init__(self, *args, **kwargs):
document_items = None
self.user = kwargs.pop('user', None)
if kwargs.get('data'):
document_items = dict((key, value) for key, value in kwargs.get('data').items() if key.startswith('document'))
self.book = kwargs.pop('book')
tag_choices = kwargs.pop('tag_choices')
super(ContactForm, self).__init__(*args, **kwargs)
choices = Tag.objects.filter(book=self.book).values_list('id', 'tag')
self.fields['tags'].choices = tag_choices
self.fields['deleted_fields'] = forms.CharField(required=False)
if document_items:
for item in document_items:
parts = item.split('_')
field_category = parts[1]
if len(parts) == 4:
if parts[3] == 'pref':
self.fields[item] = forms.BooleanField()
if parts[3] == 'label':
self.fields[item] = forms.CharField(max_length=255)
else:
if field_category == contact_constants.FIELD_TYPE_EMAIL:
self.fields[item] = forms.EmailField(max_length=255)
if field_category == contact_constants.FIELD_TYPE_URL:
self.fields[item] = forms.URLField(max_length=255)
if field_category == contact_constants.FIELD_TYPE_DATE:
self.fields[item] = forms.DateField()
else:
self.fields[item] = forms.CharField()