Skip to content

Commit

Permalink
Show validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmasuch committed Aug 18, 2024
1 parent ccfb02a commit 3d8b9fd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions examples/data_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import streamlit as st
from pydantic import BaseModel, EmailStr, Field, HttpUrl
from pydantic import BaseModel, EmailStr, Field, HttpUrl, ValidationError
from pydantic_extra_types.color import Color

import streamlit_pydantic as sp
Expand All @@ -11,6 +11,9 @@ class ExampleModel(BaseModel):
email: EmailStr


data = sp.pydantic_form(key="my_form", model=ExampleModel)
if data:
st.json(data.model_dump_json())
try:
data = sp.pydantic_form(key="my_form", model=ExampleModel)
if data:
st.json(data.model_dump())
except ValidationError as ex:
st.error(str(ex))

0 comments on commit 3d8b9fd

Please sign in to comment.