pydantic

fastapi form data with pydantic model

微笑、不失礼 提交于 2020-05-31 20:45:24
问题 I am trying to submit data from html forms and on the validate it with pydantic model. Using this code from fastapi import FastAPI, Form from pydantic import BaseModel from starlette.responses import HTMLResponse app = FastAPI() @app.get("/form", response_class=HTMLResponse) def form_get(): return '''<form method="post"> <input type="text" name="no" value="1"/> <input type="text" name="nm" value="abcd"/> <input type="submit"/> </form>''' class SimpleModel(BaseModel): no: int nm: str = "" @app

fastapi form data with pydantic model

浪子不回头ぞ 提交于 2020-05-31 20:45:08
问题 I am trying to submit data from html forms and on the validate it with pydantic model. Using this code from fastapi import FastAPI, Form from pydantic import BaseModel from starlette.responses import HTMLResponse app = FastAPI() @app.get("/form", response_class=HTMLResponse) def form_get(): return '''<form method="post"> <input type="text" name="no" value="1"/> <input type="text" name="nm" value="abcd"/> <input type="submit"/> </form>''' class SimpleModel(BaseModel): no: int nm: str = "" @app

fastapi form data with pydantic model

▼魔方 西西 提交于 2020-05-31 20:44:14
问题 I am trying to submit data from html forms and on the validate it with pydantic model. Using this code from fastapi import FastAPI, Form from pydantic import BaseModel from starlette.responses import HTMLResponse app = FastAPI() @app.get("/form", response_class=HTMLResponse) def form_get(): return '''<form method="post"> <input type="text" name="no" value="1"/> <input type="text" name="nm" value="abcd"/> <input type="submit"/> </form>''' class SimpleModel(BaseModel): no: int nm: str = "" @app