mirror of
https://github.com/fastapi/fastapi.git
synced 2026-03-27 19:22:51 -04:00
✨ Add support for forbidding extra form fields with Pydantic models (#12134)
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1b06b53267
commit
4633b1bca9
15
docs_src/request_form_models/tutorial002.py
Normal file
15
docs_src/request_form_models/tutorial002.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from fastapi import FastAPI, Form
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class FormData(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
model_config = {"extra": "forbid"}
|
||||
|
||||
|
||||
@app.post("/login/")
|
||||
async def login(data: FormData = Form()):
|
||||
return data
|
||||
Reference in New Issue
Block a user