Join my Asyncio(Python) course on Udemy 👀

Adding parameters to routes in Flask

October 9, 2020  ‐ 1 min read

Parameters in Flask routes are surrounded by < and >. The name you use for the parameter it is passed to the routing function as keyword argument.

@app.route('/<resource>')
def list_view(resource):
    return "{}".format(resource)

Converter types

You can constrain parameters using converter types. The options for converter types are string, int, float, path and uuid. You include them as follows.

@app.route('/<string:resource>')
def list_view(resource):
    return "{}".format(resource)

Flask Version

$ flask --version
Python 3.8.5
Flask 1.1.2
Werkzeug 1.0.1