Skip to content

Instantly share code, notes, and snippets.

@hamaguchi-amago
Created July 9, 2021 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamaguchi-amago/f49a825affcff52a541aeb99f8eecc92 to your computer and use it in GitHub Desktop.
Save hamaguchi-amago/f49a825affcff52a541aeb99f8eecc92 to your computer and use it in GitHub Desktop.
FastAPIで空欄のINPUTをPOSTすると発生するエラーの解消方法
from typing import Optional
from fastapi import (
APIRouter,
Form,
)
router = APIRouter()
@router.post("/ng")
async def ng_function(
user_name: str = Form(...)
):
print(user_name)
@router.post("/ok")
async def ok_function(
user_name: Optional[str] = Form(None)
):
print(user_name)
@hamaguchi-amago
Copy link
Author

ブログの記事で作成しました。
興味のある方はご覧ください。

【FastAPI】空欄のINPUTをPOSTするとエラーになる
https://neko-py.com/fastapi-form-blank-error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment