1

I have this subset object (a list of dictionnary).

quiz = [
        {'question': 'Cassandra',
         'response': 'relationnelles', 
        },

        {'question': 'MongoDB et CouchDB',
         'response': 'oriented objet,
        },
 ]


my_question = tuple(q['question'] for q in quiz)

Here is the model

class Quiz(BaseModel):
    question: Literal[my_question]
    response: str


@api.post("/postdata")
def post_data(form_data: Quiz = Depends()):
    data.append(form_data)
    return data

I would like to get the response automatically linked when I select the question item. The idea is to got the answer of the selected question dynamically Here is the actual output I got.

enter image description here

Chris
  • 18,724
  • 6
  • 46
  • 80
aba2s
  • 452
  • 2
  • 18
  • 1
    Not sure if you can do that using query parameters, but you could certainly have something similar using request body (see [here](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#body-with-multiple-examples)). You can always implement your own frontend using [`Jinja2Templates`](https://fastapi.tiangolo.com/advanced/templates/?h=templates#using-jinja2templates) and/or [`HTMLResponse`](https://fastapi.tiangolo.com/advanced/custom-response/?h=htmlresponse#return-an-htmlresponse-directly). Examples can be found [here](https://stackoverflow.com/a/70640522/17865804). – Chris Nov 09 '22 at 15:59

0 Answers0