mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
79017111aa
* new URL parsing, fix #603, fix #541 * AnyUrl parts and more tests * more coverage and db DSNs * remove DSN methods * tests for urlstr * remove debug * make AnyStr a subtype of str * fix with cython * rearranging networking code * allowing international domains, cleanup * support international domains * better URL builder * allow underscores in subdomains and domains * tests for json and schema, max length * urlstr > stricturl * updating docs * tweak docs examples * tweak docs
30 lines
593 B
Python
30 lines
593 B
Python
from pydantic import BaseModel, HttpUrl, ValidationError
|
|
|
|
class MyModel(BaseModel):
|
|
url: HttpUrl
|
|
|
|
m = MyModel(url='http://www.example.com')
|
|
print(m.url)
|
|
#> http://www.example.com
|
|
|
|
try:
|
|
MyModel(url='ftp://invalid.url')
|
|
except ValidationError as e:
|
|
print(e)
|
|
"""
|
|
1 validation error for MyModel
|
|
url
|
|
URL scheme not permitted (type=value_error.url.scheme;
|
|
allowed_schemes={'http', 'https'})
|
|
"""
|
|
|
|
try:
|
|
MyModel(url='not a url')
|
|
except ValidationError as e:
|
|
print(e)
|
|
"""
|
|
1 validation error for MyModel
|
|
url
|
|
invalid or missing URL scheme (type=value_error.url.scheme)
|
|
"""
|