Catch-All URL in flask-restful

…衆ロ難τιáo~ 提交于 2019-12-24 09:35:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!