Skip to content
Discussion options

You must be logged in to vote

It sounds like you just want the default value to be an empty string?

If that's the case, just change the value that item_description is assigned to be Form(""). The first argument of the param function is the default value assigned.

from fastapi import FastAPI, Form, testclient

app = FastAPI()


@app.post("/items")
async def create_item(
    item_description: str = Form(""),
):
    print(item_description)
    print(item_description is None)
    print(item_description == "")

Replies: 13 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
7 participants
Converted from issue

This discussion was converted from issue #2823 on February 27, 2023 23:15.