Skip to content

Tag: fastapi

FastAPI – How to get app instance inside a router?

I want to get the app instance in my router file, what should I do ? My main.py is as follows: Now I want to use app.machine_learning_model in some_router’s file , what should I do ? Answer You should store the model on the app instance using the generic app.state attribute, as described in the document…

function object has no attribute ‘connect’

Seems there’s a problem with my sql alchemy connection, don’t get why? it works sometimes and then doesn’t the next. Also vs code isn’t auto recommending sql alchemy methods, maybe I’ve set it up wrong? –database.py file main file ERROR I GET: It seems to me that the query …

Conditional call of a FastAPI Model

I have a multilang FastAPI connected to MongoDB. My document in MongoDB is duplicated in the two languages available and structured this way (simplified example): I therefore implemented two models DatasetFR and DatasetEN, each one makeS references with specific external Models (Enum) for category and tags in…

FastAPI swagger does not render because of custom Middleware?

So I have a custom middleware like this: Its objective is to add some meta_data fields to every response from all endpoints of my FastAPI app. However, when I served my app using uvicorn, and launched the swagger URL, here is what I see: With a lot of debugging, I found that this error was due to the custom m…

Send query params from Jinja template

I can’t figure out if it’s possible to pass query parameters from a static html page to a view for processing. I have now implemented the functionality I need using path parameters. I want to do the same, but with query parameters main.py events.py routes.py html It’s works with “POST …