當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。