How to use Dynamic Form Data in FastAPI application function Python?

Viewed 185

Normally If we have form data like:

<form action="/do_something" method="post">
   <label>SomeLabel</label>
   <input type="text" name="data">
   <input type="submit" value="Submit">
</form>

We can use something like this in FastAPI application

@app.post("/do_something")
def do_something(data:str = Form(...)):
   print(data)
   return ""

But when the HTML changes according to inputs like:

<form action="/do_something" method="post">
   {%for i in some_list%}
   <label>{{i}}</label>
   <input type="text" name="{{i}}">
   {%endfor%}
   <input type="submit" value="Submit">
</form>

So then what do we do for taking all these inputs as parameters for the function. Also the /docs of the FastAPI application should contain these things as text fields. Something like this: Take a look at what it should look like on /docs

Please Help Fast... Thanks

Also the known solution is something around using request and request.form()

@app.post("/do_something")
def do_something(request: Request):
   data = request.form()
   print(data)
   return ""

But in this approach nothing shows up on /docs endpoint

0 Answers
Related