from typing import Set
from fastapi import FastAPI
-from pydantic import BaseModel, UrlStr
+from pydantic import BaseModel, HttpUrl
app = FastAPI()
class Image(BaseModel):
- url: UrlStr
+ url: HttpUrl
name: str
from typing import List, Set
from fastapi import FastAPI
-from pydantic import BaseModel, UrlStr
+from pydantic import BaseModel, HttpUrl
app = FastAPI()
class Image(BaseModel):
- url: UrlStr
+ url: HttpUrl
name: str
from typing import List, Set
from fastapi import FastAPI
-from pydantic import BaseModel, UrlStr
+from pydantic import BaseModel, HttpUrl
app = FastAPI()
class Image(BaseModel):
- url: UrlStr
+ url: HttpUrl
name: str
from typing import List
from fastapi import FastAPI
-from pydantic import BaseModel, UrlStr
+from pydantic import BaseModel, HttpUrl
app = FastAPI()
class Image(BaseModel):
- url: UrlStr
+ url: HttpUrl
name: str
To see all the options you have, checkout the docs for <a href="https://pydantic-docs.helpmanual.io/#exotic-types" target="_blank">Pydantic's exotic types</a>. You will see some examples in the next chapter.
-For example, as in the `Image` model we have a `url` field, we can declare it to be instead of a `str`, a Pydantic's `UrlStr`:
+For example, as in the `Image` model we have a `url` field, we can declare it to be instead of a `str`, a Pydantic's `HttpUrl`:
```Python hl_lines="4 10"
{!./src/body_nested_models/tutorial005.py!}