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


Python forms.URLField方法代码示例

本文整理汇总了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') 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:test_urlfield.py

示例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)) 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:test_urlfield.py

示例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 
开发者ID:sfu-fas,项目名称:coursys,代码行数:11,代码来源:other.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:5,代码来源:__init__.py

示例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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:7,代码来源:__init__.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:10,代码来源:__init__.py

示例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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:10,代码来源:__init__.py

示例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,
        }) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:9,代码来源:__init__.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:field_block.py

示例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"]) 
开发者ID:labd,项目名称:wagtailstreamforms,代码行数:13,代码来源:test_fields.py

示例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 
开发者ID:Yeah-Kun,项目名称:python,代码行数:7,代码来源:__init__.py

示例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) 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:4,代码来源:test_converter.py

示例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()) 
开发者ID:project-callisto,项目名称:callisto-core,代码行数:5,代码来源:validators.py

示例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) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:10,代码来源:djangoforms.py

示例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() 
开发者ID:phildini,项目名称:logtacts,代码行数:31,代码来源:forms.py


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