Skip to content

We want to use modern python tools for our new website. We've already got our Pydantic models and FastAPI, how do we get simple forms for our models without having to create them all by hand? Django's admin interface can do it, why not FastAPI?

License

Notifications You must be signed in to change notification settings

cyanidium/pydantic-form-example

Repository files navigation

Pydantic form example

Want to generate forms from Pydantic models automatically using JSON Editor? It doesn't work "out of the box", so here are the steps you need to make it work.

I spent a lot of time looking for a solution similar to Django's admin interface for Pydantic, and there are not a lot of good choices. This combination seems like the best at the moment, and hopefully this documentation will save someone from having to figure out all the integration issues again.

It's not pretty without CSS, but it's functional

Contents

Setup

Optionally download json-editor locally (otherwise it will use a CDN):

mkdir -p static
wget -O ./static/jsoneditor.min.js https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js

Testing

To run all tests, and generate screenshots of the pages, run:

playwright install firefox
for i in */test.py; do uv run $i; done

About

We want to use modern python tools for our new website. We've already got our Pydantic models and FastAPI, how do we get simple forms for our models without having to create them all by hand? Django's admin interface can do it, why not FastAPI?

Resources

License

Stars

Watchers

Forks

Languages