Files
pydantic/docs/examples/urls.py
T
Samuel Colvin 79017111aa new URL parsing (#755)
* 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
2019-09-02 11:37:33 +01:00

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)
"""