Hello.
I am trying to create a Catch-All function which serves every URL. I am following the example from http://flask.pocoo.org/snippets/57/
Here is the code snippet:
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()
This code snippet does not catch all of the URLs. Am I missing something here?
Thanks.
Which url doesn't it catch?
Thanks for the reply, David. I found the cause of my problem.
This is what I was doing originally:
from flask import Flask app = Flask(__name__, static_url_path='') @app.route('/', defaults={'path': ''}) @app.route('/<path:path>') def catch_all(path): return 'You want path: %s' % path if __name__ == '__main__': app.run()
static_url_path='' was breaking the code...
I would not recommend setting static_url_path if you are creating a catch-all function.
Is there a way to have a static_url_path which isn't None and a catch-all function working harmoniously? What's the reason for static_url_path interfering with catch-all routing?
I am waiting for answer to question raised by @FredDavison.
Most helpful comment
Is there a way to have a
static_url_pathwhich isn'tNoneand a catch-all function working harmoniously? What's the reason forstatic_url_pathinterfering with catch-all routing?