Is there a way to create an Html form from a pydantic model?
Let's start with an easy example.
I have a model User
:
from pydantic import BaseModel
class User(BaseModel):
id: int
name: str = 'Jane Doe'
and some magic function that transforms the User
model into the following form:
<form>
<label for="id">ID:</label><br>
<input type="number" id="id" name="id"><br>
<label for="name">Name:</label><br>
<input type="text" id="name" name="name">
</form>
Of course, this can be arbitrarily complex e.g. when your model has List
s which might be a Dropdown selection field.
So I'm interested if this is somehow already possible? I would be using this in the context of FastAPI.