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


Python forms.URLField类代码示例

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


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

示例1: _extract_url

 def _extract_url(cls, text_url_field):
     '''
     >>> url_text = 'http://www.google.com blabla'
     >>> FacebookAPI._extract_url(url_text)
     u'http://www.google.com/'
     
     >>> url_text = 'http://www.google.com/'
     >>> FacebookAPI._extract_url(url_text)
     u'http://www.google.com/'
     
     >>> url_text = 'google.com/'
     >>> FacebookAPI._extract_url(url_text)
     u'http://google.com/'
     
     >>> url_text = 'http://www.fahiolista.com/www.myspace.com/www.google.com'
     >>> FacebookAPI._extract_url(url_text)
     u'http://www.fahiolista.com/www.myspace.com/www.google.com'
     
     >>> url_text = u"""http://fernandaferrervazquez.blogspot.com/\r\nhttp://twitter.com/fferrervazquez\r\nhttp://comunidad.redfashion.es/profile/fernandaferrervazquez\r\nhttp://www.facebook.com/group.php?gid3D40257259997&ref3Dts\r\nhttp://fernandaferrervazquez.spaces.live.com/blog/cns!EDCBAC31EE9D9A0C!326.trak\r\nhttp://www.linkedin.com/myprofile?trk3Dhb_pro\r\nhttp://www.youtube.com/account#profile\r\nhttp://www.flickr.com/\r\n Mi galer\xeda\r\nhttp://www.flickr.com/photos/wwwfernandaferrervazquez-showroomrecoletacom/ \r\n\r\nhttp://www.facebook.com/pages/Buenos-Aires-Argentina/Fernanda-F-Showroom-Recoleta/200218353804?ref3Dts\r\nhttp://fernandaferrervazquez.wordpress.com/wp-admin/"""        
     >>> FacebookAPI._extract_url(url_text)
     u'http://fernandaferrervazquez.blogspot.com/a'
     '''
     import re
     text_url_field = text_url_field.encode('utf8')
     seperation = re.compile('[ ,;\n\r]+')
     parts = seperation.split(text_url_field)
     for part in parts:
         from django.forms import URLField
         url_check = URLField(verify_exists=False)
         try:
             clean_url = url_check.clean(part)
             return clean_url
         except ValidationError, e:
             continue
开发者ID:aidaeology,项目名称:Django-facebook,代码行数:34,代码来源:api.py

示例2: _extract_url

 def _extract_url(cls, text_url_field):
     '''
     >>> url_text = 'http://www.google.com blabla'
     >>> FacebookAPI._extract_url(url_text)
     u'http://www.google.com/'
     
     >>> url_text = 'http://www.google.com/'
     >>> FacebookAPI._extract_url(url_text)
     u'http://www.google.com/'
     
     >>> url_text = 'google.com/'
     >>> FacebookAPI._extract_url(url_text)
     u'http://google.com/'
     
     >>> url_text = 'http://www.fahiolista.com/www.myspace.com/www.google.com'
     >>> FacebookAPI._extract_url(url_text)
     u'http://www.fahiolista.com/www.myspace.com/www.google.com'
     '''
     import re
     text_url_field = str(text_url_field)
     seperation = re.compile('[ |,|;]+')
     parts = seperation.split(text_url_field)
     for part in parts:
         from django.forms import URLField
         url_check = URLField(verify_exists=False)
         try:
             clean_url = url_check.clean(part)
             return clean_url
         except ValidationError, e:
             continue
开发者ID:Manduka,项目名称:Django-facebook,代码行数:30,代码来源:facebook_api.py

示例3: test_urlfield_7

 def test_urlfield_7(self):
     f = URLField()
     self.assertEqual("http://example.com", f.clean("http://example.com"))
     self.assertEqual("http://example.com/test", f.clean("http://example.com/test"))
     self.assertEqual(
         "http://example.com?some_param=some_value", f.clean("http://example.com?some_param=some_value")
     )
开发者ID:homberger,项目名称:django,代码行数:7,代码来源:test_urlfield.py

示例4: get_url_informations

def get_url_informations(url):
    """Get informations about a url"""

    error_invalid = False, {"error": _(u"Invalid URL")}
    error_exist = False, {"error": _(u"This URL has already been submitted")}
    error_connect = False, {"error": _(u"Failed at opening the URL")}

    # Check url is valid
    try:
        url_field = URLField()
        clean_url = url_field.clean(url)
    except:
        return error_invalid

    # Check url exist
    if exist_url(clean_url):
        return error_exist

    # Get informations
    req = requests.get(clean_url)
    if 200 == req.status_code:
        final_url = req.url
        soup = BeautifulSoup(req.text)
        title = soup.title.string
        description = soup.findAll("meta", attrs={"name": re.compile("^description$", re.I)})[0].get("content")
    else:
        return error_connect

    # Check final url exist if different from clean url
    if final_url != clean_url:
        if exist_url(final_url):
            return error_exist

    return True, {"url": final_url, "title": title, "description": description}
开发者ID:tricky21,项目名称:prswb,代码行数:34,代码来源:models.py

示例5: test_urlfield_7

 def test_urlfield_7(self):
     f = URLField()
     self.assertEqual('http://example.com', f.clean('http://example.com'))
     self.assertEqual('http://example.com/test', f.clean('http://example.com/test'))
     self.assertEqual(
         'http://example.com?some_param=some_value',
         f.clean('http://example.com?some_param=some_value')
     )
开发者ID:277800076,项目名称:django,代码行数:8,代码来源:test_urlfield.py

示例6: test_urlfield_10

 def test_urlfield_10(self):
     """URLField correctly validates IPv6 (#18779)."""
     f = URLField()
     urls = (
         'http://[12:34::3a53]/',
         'http://[a34:9238::]:8080/',
     )
     for url in urls:
         self.assertEqual(url, f.clean(url))
开发者ID:277800076,项目名称:django,代码行数:9,代码来源:test_urlfield.py

示例7: test_url_regex_ticket11198

    def test_url_regex_ticket11198(self):
        f = URLField()
        # hangs "forever" if catastrophic backtracking in ticket:#11198 not fixed
        with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
            f.clean('http://%s' % ("X" * 200,))

        # a second test, to make sure the problem is really addressed, even on
        # domains that don't fail the domain label length check in the regex
        with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
            f.clean('http://%s' % ("X" * 60,))
开发者ID:277800076,项目名称:django,代码行数:10,代码来源:test_urlfield.py

示例8: test_urlfield_9

 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:
         # Valid IDN
         self.assertEqual(url, f.clean(url))
开发者ID:277800076,项目名称:django,代码行数:19,代码来源:test_urlfield.py

示例9: get_url_informations

def get_url_informations(url):
    """Get informations about a url"""

    error_invalid = False, {'error': _(u'Invalid URL')}
    error_exist = False, {'error': _(u'This URL has already been submitted')}
    error_connect = False, {'error': _(u'Failed at opening the URL')}

    # Check url is valid
    try:
        url_field = URLField()
        clean_url = url_field.clean(url)
    except:
        return error_invalid

    # Check url exist
    if exist_url(clean_url):
        return error_exist

    # Get informations
    req = requests.get(clean_url)
    if req.status_code == 200:
        final_url = req.url
        soup = BeautifulSoup(req.text)
        title = soup.title.string
        description = soup.findAll('meta',
            attrs={'name': re.compile("^description$", re.I)})[0].get('content')
    else:
        return error_connect

    # Check final url exist if different from clean url
    if final_url != clean_url:
        if exist_url(final_url):
            return error_exist

    return True, {
        'url': final_url,
        'title': title,
        'description': description,
    }
开发者ID:n1k0,项目名称:prswb,代码行数:39,代码来源:utils.py

示例10: test_urlfield_5

 def test_urlfield_5(self):
     f = URLField(min_length=15, max_length=20)
     self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" />')
     with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 15 characters (it has 12).'"):
         f.clean('http://f.com')
     self.assertEqual('http://example.com', f.clean('http://example.com'))
     with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 37).'"):
         f.clean('http://abcdefghijklmnopqrstuvwxyz.com')
开发者ID:277800076,项目名称:django,代码行数:8,代码来源:test_urlfield.py

示例11: test_urlfield_normalization

 def test_urlfield_normalization(self):
     f = URLField()
     self.assertEqual(f.clean('http://example.com/     '), 'http://example.com/')
开发者ID:AvaniLodaya,项目名称:django,代码行数:3,代码来源:test_extra.py

示例12: test_urlfield_2

 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:homberger,项目名称:django,代码行数:16,代码来源:test_urlfield.py

示例13: test_urlfield_2

 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:277800076,项目名称:django,代码行数:16,代码来源:test_urlfield.py

示例14: test_urlfield_not_string

 def test_urlfield_not_string(self):
     f = URLField(required=False)
     with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
         f.clean(23)
开发者ID:277800076,项目名称:django,代码行数:4,代码来源:test_urlfield.py

示例15: test_urlfield_1

 def test_urlfield_1(self):
     f = URLField()
     self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" />')
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean('')
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean(None)
     self.assertEqual('http://localhost', f.clean('http://localhost'))
     self.assertEqual('http://example.com', f.clean('http://example.com'))
     self.assertEqual('http://example.com.', f.clean('http://example.com.'))
     self.assertEqual('http://www.example.com', f.clean('http://www.example.com'))
     self.assertEqual('http://www.example.com:8000/test', f.clean('http://www.example.com:8000/test'))
     self.assertEqual('http://valid-with-hyphens.com', f.clean('valid-with-hyphens.com'))
     self.assertEqual('http://subdomain.domain.com', f.clean('subdomain.domain.com'))
     self.assertEqual('http://200.8.9.10', f.clean('http://200.8.9.10'))
     self.assertEqual('http://200.8.9.10:8000/test', f.clean('http://200.8.9.10:8000/test'))
     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('com.')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
         f.clean('.')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
         f.clean('http://.com')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
         f.clean('http://invalid-.com')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
         f.clean('http://-invalid.com')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
         f.clean('http://inv-.alid-.com')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
         f.clean('http://inv-.-alid.com')
     self.assertEqual('http://valid-----hyphens.com', f.clean('http://valid-----hyphens.com'))
     self.assertEqual(
         'http://some.idn.xyz\xe4\xf6\xfc\xdfabc.domain.com:123/blah',
         f.clean('http://some.idn.xyzäöüßabc.domain.com:123/blah')
     )
     self.assertEqual(
         'http://www.example.com/s/http://code.djangoproject.com/ticket/13804',
         f.clean('www.example.com/s/http://code.djangoproject.com/ticket/13804')
     )
     with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
         f.clean('[a')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'"):
         f.clean('http://[a')
开发者ID:277800076,项目名称:django,代码行数:51,代码来源:test_urlfield.py


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