Flask-restful 中的 Catch-All URL

Ahm*_*shi 5 python flask flask-restful

Flask具有Catch-All URL功能

from flask import Flask app = Flask(__name__)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
    return 'You want path: %s' % path

if __name__ == '__main__':
    app.run()
Run Code Online (Sandbox Code Playgroud)

稍微示范一下..

% curl 127.0.0.1:5000          # Matches the first rule
You want path:  
% curl 127.0.0.1:5000/foo/bar  # Matches the second rule
You want path: foo/bar
Run Code Online (Sandbox Code Playgroud)

我怎样才能在 中拥有相同的功能flask-restful

小智 4

cricket_007 发表的评论解决了这个问题:

如果您需要接受任何带斜杠的内容,那么api.add_resource(Endpoint, '/<path:content>')应该可以