Skip to content
Advertisement

Tag: starlette

How to get route’s name using FastAPI/Starlette?

How can I get the name of a route/endpoint using FastAPI/Starlette? I have access to the Request object and I need this information in one of my middlewares. For example, if I hit services/1, I should then be able to get the abc name. Is this possible in FastAPI? Update 1: Output of request.scope Update 2: Providing middleware code where

How to pass URL as a path parameter to a FastAPI route?

I have created a simple API using FastAPI, and I am trying to pass a URL to a FastAPI route as an arbitrary path parameter. When I test it, it doesn’t work and throws an error. I am testing it this way: Answer Option 1 You can simply use the path convertor to capture arbitrary paths. As per Starlette documentation,

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 documentation (see State class implementation

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 /event/invite/15/sender/3 HTTP/1.1” as a sample Try with query params And

Advertisement