Take the 2-minute tour ×

I have a simple Flask route:

def get_dir(path):
    # do some stuff
    return path

This works fine for urls of the form localhost:5000/my_path/.

However, I really want this to work with an indeterminate amount of subpaths, like:


so that my path variable contains the everything after the route as a string:


I guess I need to ignore slashes when capturing the variable, but I am new to Flask and I'm not sure how to tackle this.

Any help would be much appreciated.

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

Like this:

@app.route('/', defaults={'path': ''})

You can typecast (well kinda) the arguments in three ways, path, int and float, nothing means string.

<int:stuff> # accepts integers (typecasts)
<float:stuff> # like int but for floating point values
<path:stuff> # like the default but also accepts slashes
<stuff> # Default

Sources: http://flask.pocoo.org/snippets/57/

share|improve this answer
Thanks for the great answer and supporting docs! –  Darwin Tech Feb 27 '13 at 16:57
add comment

Your Answer


