Routing: matching an arbitrary path

I want to serve URLs like

/content/foo.pdf
/content/some/path/xx.pdf
/content/a/very/long/path/to/some/xx.pdf

through one endpoint registered for the route /content.

How can I much arbitrary sub paths after /content?

When creating the routes, there is a path type and a custom regex that can be used to match some patterns.


@app.route("/content/<custom_path:path>/<pdf:[a-zA-Z0-9]+.pdf>")
def method(request, custom_path, pdf):
    return json({
        "path": custom_path,
        "pdf": pdf
    })
1 Like