It seems Flask doesn’t support routes with a URI encoded component. I’m curious if I’m doing something wrong, or if there is a special flag I need to include.
My route looks something like this:
@app.route('/foo/<encoded>/bar/')
def foo(encoded):
# ...
pass
The URL that this should match can look like these:
http://foobar.com/foo/xxx/bar/ # matched correctly, no URI component
http://foobar.com/foo/x%2Fx%2Fx%2F/bar/ # not matched correctly, URI component
Former URL works, latter spits out a lovely 404.
Thanks!
Add
pathto your url rule:@app.route('/foo/<path:encoded>/bar/')Update per comment: The route API docs are here: http://flask.pocoo.org/docs/api/#flask.Flask.route. The underlying classes that implement the
pathstyle route converter are here: http://werkzeug.pocoo.org/docs/routing/#custom-converters (this is one of the really nice parts of pocoostan.) As far as the trailing slashes, there are special rules that amount to:Also keep in mind that if you are on Apache and are expecting a slash-trailed url, ie a bookmarklet that submits to
http://ex.com/foo/<path:encoded>/barandencodedgets something with double slashes, Apache will convert multiple slashes to a single one.