I am using the catch-all url pattern in my Flask route. I want the view to ignore (throw a 404 error) any path that starts with /api. How can I do this?
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
return 'Hello, World!'
Check if the route starts with the prefix, then cancel if it does.
from flask import abort if path.startswith('api'): abort(404)