Catch-All URL in flask-restful

时间:2016-09-21 23:03:36

标签: 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()
     

一点点演示......

% 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

如何在flask-restful中使用相同的功能?

1 个答案:

答案 0 :(得分:0)

The comment posted by cricket_007解决了问题:

  

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