问题
There is a Catch-All URL ability in Flask
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()A little demonstration..
% 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
How can I have the same functionality in flask-restful?
回答1:
The comment posted by cricket_007 solved the problem:
If you are needing to accept anything with slashes, then
api.add_resource(Endpoint, '/<path:content>')should work
来源:https://stackoverflow.com/questions/39627804/catch-all-url-in-flask-restful