Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


Flask route all path with slash

27 Aug 2020 » web

update 30sep23

https://github.com/pallets/werkzeug/issues/2783

class EverythingConverter(PathConverter):
    regex = '.*?'
    part_isolating = False

update 27sep23

be sure to pip3 install werkzeug==2.0.3

https://stackoverflow.com/questions/24000729/flask-route-using-path-with-leading-slash

import werkzeug
from werkzeug.routing import PathConverter
from packaging import version

# whether or not merge_slashes is available and true
MERGES_SLASHES = version.parse(werkzeug.__version__) >= version.parse("1.0.0")

class EverythingConverter(PathConverter):
    regex = '.*?'

app.url_map.converters['everything'] = EverythingConverter

config = {"merge_slashes": False} if MERGES_SLASHES else {}
@api.route('/records/<hostname>/<metric>/<everything:context>', **config)