0

I am trying to create a small API in Flask requiring two different parameters. A ticker and a key (for authentication).

Here is how my route is defined:

api_bp = Blueprint("api", __name__, url_prefix="/api")


@api_bp.route("/1.0/<string:ticker>?key=<string:key>", methods=["GET"])
def some_function(ticker:str, key:str):
    ...

However I am getting a 404 not found error. When I remove the second part and make the url just:

@api_bp.route("/1.0/<string:ticker>", methods=["GET"])

everything works fine. Why is this?

APorter1031
  • 2,107
  • 6
  • 17
  • 38

1 Answers1

1

Request path parameters are past as in your working example. Query parameters (all after the ?) work as follows. You do not add them in the app or blueprint route definition, you just get the value by getting the request arguments:

request.args.get('key', None)

where value is None if 'key' does not exist.

gittert
  • 1,238
  • 2
  • 7
  • 15