Reputation: 7419
I can define many routes in flask
@app.route('/')
@app.route('/schedules/<params>', methods=["GET"])
but how to intercepted any other routes that not defined in my app.
Upvotes: 0
Views: 909
Reputation: 1034
I've implemented a catch_all functionality that will take the path requested and try to return an html file with that name, if it fails it will redirect to index.
@WebApp.app.route('/<path:path>', methods=['GET', 'POST'])
def catch_all(path):
url = path+".html"
try:
return flask.render_template(url)
except:
return flask.redirect(flask.url_for('index'))
Upvotes: 0
Reputation: 390
How about the following ?
@app.route('/<generic>')
You may also be looking for a way to handle 404 errors
@app.errorhandler(404)
Upvotes: 3