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